JavaScript JavaScript Basics Working With Numbers The Mad Libs Challenge Revisited

niels Lostaunau
niels Lostaunau
635 Points

can't understand line 2

I don't understand the quotation marks and brackets

4 Answers

niels Lostaunau
niels Lostaunau
635 Points

' [' is a string

  • questions + is a variable 'questions left]' is another string

it made sense when I looked at it next morning thank you for your help !

Dominique Mitchell
Dominique Mitchell
3,987 Points

Thank you for this explanation! I was stuck on that exact same thing.

Agnes Demes
Agnes Demes
6,606 Points

it might be clearer like this

// initital variable to hold questions declaired and intitialised to the value of 3
var questions =3;
/*new variable called questionsLeft declaired
this varriable will hold the string [ + the value of questions varriable + ] string so when it is printed it will display like this [ 2 questions left]
*/
var questionsLeft = '[ ' + questions + ' questions left ]';
// i
Agnes Demes
Agnes Demes
6,606 Points

yes thats it, well done! it sometimes good to take a break and look at it with fresh eyes.

Agnes Demes
Agnes Demes
6,606 Points

Hi, so at line 2 the teacher initially types a string format which he would like to apply late then he deletes line 2 at 1.02 as it was there just for reference. then the new line 2 is he declaires a new varriable called questionsLeft and makes it equal to , the questions varriable which is =3 at this point plus the to be printed string " questions left"

so when in use later in the program this code will display the current state of the questionsLeft varriable ( could be =1 or=2 or=3) and the string eg: 2 questions left hope this helps