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

  • Home
  • SEARCH
  • 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 170977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:54:20+00:00 2026-05-11T12:54:20+00:00

So I am doing a small, simple project for my class and for some

  • 0

So I am doing a small, simple project for my class and for some reason I can’t access a value using a variable.

This is my class: (I am having problems with the getAnswer method, in particular the answerArray array)

#Create random fact array class RandomFact     def initialize()         @randomNum = rand(5)     end      def getQuestion         randomNum = @randomNum         questionArray = Array.new         questionArray[0] = 'Do you liek mudkipz?'         questionArray[1] = 'Question2'         questionArray[2] = 'Three'         questionArray[3] = 'Reddit'         questionArray[4] = '4chan'          puts questionArray[randomNum]         return randomNum     end      def getAnswer(randomNum,answer)         answerArray = Array.new         answerArray[0] = 'one'         answerArray[1] = 'two'         answerArray[2] = 'three'         answerArray[3] = 'four'         answerArray[4] = 'five'          return answerArray[randomNum]     end  end 

This is my class to the class:

    randomNum = cgi['randomNum']     answer = cgi['answer']     puts newQuestion.getAnswer(randomNum,answer) 

Now the thing is that randomNum holds a value from a previous form. If I print out randomNum right under where I pull the value from the form I get it.
if I print out randomNum inside of the method getAnswer I get it.
If I print out answerArray[0] I get a value.
If I print out answerArray[randomNum] I get nothing.

It is pretty much an exact copy of the getQuestion method from above and that one works. Any input?

  • 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. 2026-05-11T12:54:21+00:00Added an answer on May 11, 2026 at 12:54 pm

    The random number is probably coming in as a string from your CGI. Cast it to an integer using randomNum.to_i and you’ll be set.

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

Sidebar

Ask A Question

Stats

  • Questions 101k
  • Answers 101k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If it's only about getting the number of records (rows)… May 11, 2026 at 8:09 pm
  • Editorial Team
    Editorial Team added an answer You should try: var new_width = $('#book_table').width() + 407; $('body').width(new_width);… May 11, 2026 at 8:09 pm
  • Editorial Team
    Editorial Team added an answer SELECT poster.*, COUNT(DISTINCT odgovori.author) AS different FROM poster JOIN odgovori… May 11, 2026 at 8:09 pm

Related Questions

I am only one person working on project - so I am developer without
I was listening to a podcast recently that was discussing at length the short
I have a small project I am doing in Python using web.py. It's a
I'm doing a raytracer hobby project, and originally I was using structs for my

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.