5/7 finally done


#1

I used this

// Check if the user is ready to play!
console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'");
console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'");
var userAnswer = prompt("Do you want to race Bieber on stage?");

if (userAnswer === "yes") {
console.log("You and Bieber start racing. It's neck and neck! You win by a shoelace!");
} else {
console.log("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.");
}

confirm("Ready to play?");
var age = prompt("What's your age");
if (age < 13) {
console.log("You're allowed to play but you take no responsibility.");
} else {
console.log("Have fun");
}

answer ok and then 13


#2

Nice...
but do you have any questions ??


#3

No Thanks , I'll let you know if any. :smile:


#4

I have a question could you help me please. The task number 5(The story heats up). It says that (ReferenceError: Invalid left-hand side in assignment) But I just don't get it. where is my mistake.

// Check if the user is ready to play!
confirm("Let it be!");
var age = prompt("What's your age?");
if(age < 13)
{
console.log("age = 13")
}
else
{
console.log("age < 13")
}
console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'");
console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'")
var userAnswer = prompt("Do you want to race Bieber on stage?");
if("userAnswer" = "yes");
console.log("You and Bieber start racing. It's neck and neck! You win by a shoelace!"); {
} else {
console.log("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'");


#5

@humsterbuster,

== 1 ==

A semi-colon-; is an End-of-Statement-indicator to the Javascript Interpreter.
( do NOT use a semi-colon-; in an IF ELSE statement-structure !!! )

== 2 ==

var testVar = 1; you use a so-called assignment-operator =
You assign the number Value 1 to the variable testVar
( from now on, if you use testVar in your code, the Javascript-interpreter evaluates the =variable= testVar and will be using its associated number Value 1 )
console.log("The value of testVar is " + testVar ) ==>output=> The value of testVar is 1
( also read
= https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var
= https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators

== 3 ==

The IF ELSE statement structure

if ( condition ) {
    //Begin of IF code-block
   //IF has a =condition= part
   //=condition= Is an expression that evaluates to true or false.
   // this code-block will be executed if the condition evaluates to a Boolean =true=
  
   //your code

   //End of IF code-block
}
else {
   //Begin of ELSE code-block
   // an ELSE itself has NO condition-part
   // ELSE code-block will be executed if the IF-condition evaluated to Boolean =false=

   //your code

  //End of ELSE code-block`
}

( also read https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else )

== 4 ==

Operators which are used in this Javascript course
in the order of their evaluation

Operator type           Individual operators
====================    ====================
multiply/divide         * / % 
addition/subtraction    + - 
relational              < <= > >= 
equality                == != === !== 
logical-and             && 
logical-or              || 
assignment              = += -= *= /=  
comma                   ,

Also have a read
= https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators
( Assignment-, Comparison-, Arithmetic-, Relational- and Logical-operators )


#6

@humsterbuster,

// Check if the user is ready to play!
confirm("Let it be!");
// A window-popup with an Ok-button and a Cancel-button
// confirm is a statement, ended by a semi-colon-;
//
var age = prompt("What's your age?");
// The =return _string_ Value= of the prompt-window-popup 
// is assigned to the VARIABLE =age=
// The prompt-window-popup has an Ok-button and a Cancel-button
// VAR-declaration is a statement ended by a semi-colon-;
//
if(age < 13)  {
  //Begin of IF code-block
  // IF-condition uses the relational-operator =less-than=
  // if =age= less than 13 evaluates to Boolean TRUE
  // then the IF code-block will be executed

  //your code
  console.log("You are younger than 13, parental guidance is advised. Age given is: " age);
  //console.log() is a statement, and is ended with a semi-colon-;

  //End of IF code-block
} 
else  {
  //Begin of ELSE code-block
  //this code-block will be executed if the IF-condition evaluated to Boolean FALSE
  // in this case, if =age= greater-equals 13

  // Your code
  console.log("We wish you all the best in our Adventure....");
  //console.log() is a statement, and is ended with a semi-colon-;

  //End of ELSE code-block
}

console.log("You are at a Justin Bieber concert," +
                   " and you hear this lyric 'Lace my shoes off, start racing.'");
console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'");
//console.log() is a statement, and is ended with a semi-colon-;
var userAnswer = prompt("Do you want to race Bieber on stage?");
if( userAnswer === "yes") { //semi-colon was removed !!
  // Begin of IF-code-block
  //The IF-condition uses a =strict comparison= 
  //comparing the associated-Value-of-userAnswer-VARIABLE to
  // the =string Value= "yes"
  // if the =comparison= evaluated to a Boolen TRUE
  // this IF code-block is executed

   //your code
   console.log("You and Bieber start racing. It's neck and neck! You win by a shoelace!");

  //End of IF code-block
}
else {
 //Begin of ELSE code-block
 //ELSE has no condition
 //ELSE code-block will be executed, 
  //if the =strict comparison= in the IF-condition evaluated to Boolean FALSE

  //Your code
  console.log("Oh no! Bieber shakes his head and sings "+
             "'I set a pace, so I can race without pacing.'");

  //End of ELSE code-block
}

28. Conclusion: Part 2 *IF, ELSE STATEMENTS*
Cant do 2
#7

I have positive result after this:
// Check if the user is ready to play!
confirm ("I am ready to play!");
var age = prompt("What's your age");
if (age < 13)
{console.log ("Play with you own responsibility")
}
else (age > 13)
{console.log ("You are in our party. Congratulations!")
}
console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'");
console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'")
var userAnswer = prompt("Do you want to race Bieber on stage?")
if (userAnswer === "yes"){
console.log("You and Bieber start racing. It's neck and neck! You win by a shoelace!")
}
else {
console.log("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'")
}