Elliot DenvirPro Student 1,732 Points
Is Num defined?
I am confused as to where the variable num is defined. At what point during the code or the game is num given a value, except for in the line var num = num || 4. And if this is the only point then will num always equal 4?
Erik Nuber20,627 Points
I haven't been thru the this particular lesson but, I looked at the code.
The function random_number is called on both line 10 and 27 of the initial JS file.
on line 10 4 is also passed into the function so num would be set to 4 but, on line 27 it says
this means that the random_number function is being called and num = choices.length in this case. So num doesn't always equal 4, it can be equal to the number of items in the choices array within the final function get_answer.
It looks like this is done because a user can enter up to four choices so num could be equal to 1, 2, 3, or 4