Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8118819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:36:50+00:00 2026-06-06T04:36:50+00:00

So I have code: puts ‘What is your name?(Enter in field below)’ input =

  • 0

So I have code:

puts 'What is your name?(Enter in field below)'
input = gets.chomp
puts 'end'
occupationslist = ['Engineer', 'Clerk', 'Doctor', 'Demolition Expert', 'Athlete', 'None',]
oclistlength = occupationslist.length
rand1 = rand(oclistlength)
occupation = ocupationslist[rand1]
def occupations
  puts input
  puts 'Occupation: ' + occupation
  puts 'Rating: ' + rand(1-12).to_s  
end
occupations

It is supposed to display your name(that you entered), a random occupation, and a random rating but I don’t know what is wrong with it.
This is the satisfactory output:

prints "What is your name?".
(gets user input)
prints out the input.
prints out a random 'occupation'(from the list in the array above).
prints out the 'Rating: ' - a random number from 0 to 12.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T04:36:52+00:00Added an answer on June 6, 2026 at 4:36 am

    input and occupation are defined outside the scope of the occupationsfunction. Either declare it as a global variable with $input and $occupation, declare it inside the function or pass the variables as arguments to the function (as Lee suggested):

    puts 'What is your name?(Enter in field below)'
    $input = gets.chomp
    puts 'end'
    occupationslist = ['Engineer', 'Clerk', 'Doctor', 'Demolition Expert', 'Athlete', 'None',]
    oclistlength = occupationslist.length
    rand1 = rand(oclistlength)
    $occupation = occupationslist[rand1]
    def occupations
      puts $input
      puts 'Occupation: ' + $occupation
      puts 'Rating: ' + rand(1-12).to_s  
    end
    occupations
    

    Besides, there was a typo: in occupation = occupationslist[rand1] instead of oc*c*upationslist[rand1] you wrote ocupationslist[rand1] (without the ‘c’).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have ruby code like this: module Hello class Hi def initialize() puts self.module.name
I have some code that does a bunch of HTTP GETs, POSTs, and PUTs
I have following code: module CarHelper def call_helpline puts Calling helpline... end end class
I have such code reg = /(.+)_path/ if reg.match('home_path') puts reg.match('home_path')[0] end This will
I have the code: require 'open-uri' print Enter a URL: add = gets added
Let's say we have code looks like this module TM def aa puts aa
I have some code that loads an image file off the web and puts
I have some code that creates a bunch of UITextViews and puts them into
I have this JavaScript code that creates a table, and puts in the rows
I have the following code: #!/usr/bin/ruby class Person def self.speak p = self.new puts

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.