Monday 31 January 2011

Week 1 Exercise 2.5 If Else Statement

My first attempt was wrong because when I use Logical Or, I for got to put the whole expression

var answer = prompt("What is the value of 2+2?");
if (answer == "4")
  alert ("well done, you are great with maths!");
else if (answer == "3" || "5")
  alert ("Almost!");
else
  alert ("You are too stupid to live");


The correct answer is this:

var answer = prompt("What is the value of 2+2?");
if (answer == "4")
  alert ("well done, you are great with maths!");
else if (answer == "3" || answer == "5")
  alert ("Almost!");
else
  alert ("You are too stupid to live");

No comments:

Post a Comment