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 7582363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:25:04+00:00 2026-05-30T18:25:04+00:00

2 Questions, firstly I have this code: function Question(container, question_list, chosenAnswer) { this.container =

  • 0

2 Questions, firstly I have this code:

    function Question(container, question_list, chosenAnswer) {
    this.container = container.empty();
    this.question_list = question_list;

    if(question_list.length == 1) {

        container.append('<div class="answer">' + question_list[0] + '</div>'); 

    } else if (question_list.length == 2) {

        for(var i=0;i<question_list.length;i++){
            container.append('<div class="two_q'+(i+1)+'">' + question_list[i] + '</div>');
        }
        addClickOn(container, chosenAnswer);


    } else {

        for(var i=0;i<question_list.length;i++){
            container.append('<div class="four_q'+(i+1)+'">' + question_list[i] + '</div>');
        }
        addClickOn(container, chosenAnswer);
    }
}

function addClickOn(container, chosenAnswer)
{
    this.container = container;
    $(container.children()).on('click', function() {
        selected = $(this);
        chosenAnswer= $(this).index();
        selected.siblings().fadeOut();
        selected.animate({
            width: container.width(),
            height: container.height()
        });
        selected.fadeOut();
    });
}


    var question_list1 = ["Question 1", "Question 2", "Question 3", "Question 4"];
    var question_list2 = ["Statement1", "Statement2"];
    var answer = ["Answer"];
    var chosenAnswer;

new Question($('div.question_container'), question_list2);
console.log(chosenAnswer);
  1. Why is chosenAnswer undefined on the console log? I haven’t defined it, but I have passed it through the functions till it gets set on the click event.

  2. When one of the boxes is clicked and the animation has finished, I then want to return this chosenAnswer and repeat the Question function with a new array. How do I do this?

Thanks,

Rick

  • 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-05-30T18:25:05+00:00Added an answer on May 30, 2026 at 6:25 pm

    JavaScript is a call by value language. You can’t modify the value of a variable in the calling context like you can with a C++ &foo reference parameter.

    If you made “chosenAnswer” an object, then the function could use the reference to that object passed in as a parameter to modify the object contents. It’s hard to say exactly how to fix your code because it’s so unidiomatic.

    Your use of this in “addClickOn()” is incorrect also. Again, it’s hard to say what the code should do instead, but this in that function won’t refer to anything useful because of the way the function is called.

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

Sidebar

Related Questions

Ok, firstly I have the following code working.. although my question is this; should
Firstly, I do not have any malicious intent out of this question. I would
I have a modeling question related to profiles. Firstly, I have looked into using
Firstly, This might seem like a long question. I don't think it is... The
Firstly I am new to android and Java so this is a beginners question.
The questions says everything, take this example code: <ul id=css-id> <li> <something:CustomControl ID=SomeThingElse runat=server
I have the following code #include <iostream> using namespace std; class Object { public:
Hi i have a couple of question about using named pipes. Firstly, when trying
Firstly, this DB question could be a bit DB agnostic, but I am using
Firstly, I realise that this is a very similar question to this one: Which

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.