External Exam Download Resources Web Applications Games Recycle Bin

Choices

condition.js

age = 12;
if (age < 15){
    alert("You are not old enough to see the movie.");
}

else.js

age = 18;
if (age < 15){
    alert("You are not old enough to see the movie.");
}
else{
    alert("Here is your ticket, enjoy the movie.");
}

nested.js

age = parseInt(prompt("How old are you?"));
if (age < 17){
    alert("Go study.");
}
else{
    if (age < 65){
        alert("Get a job.");
    }
    else
    {
        alert("Retire.");        
    }
}
  1. Write a program that sets a variable age to 15. Then check this age to see if I am under 18, and if I am, tell me "You are not old enough to see the movie."

  2. Write a program that sets a variable cost to 20.00, as follows: cost = 20.00;. This will represent $20. Now check if the cost is less than $30. If it is, say "Bargain", if not, say "Ripoff"

  3. Write a program that reads an integer variable named sticks from the user, using sticks = parseInt(prompt("Enter sticks: "));. If I have at least 7 sticks in Minecraft, I can craft a wooden ladder. If I can craft a wooden ladder, say "You can craft a wooden ladder." Otherwise don't say anything.

  4. Write a program that checks students age at a student disco. If the student is aged 18 or over, they are not invited into the disco. Let them know.

  5. Write a program that tells me whether a number is positive or negative (i.e. less than 0).

  6. Add another choice to the nested / age program, so that if I am between the age of 45 and 65, the program should say Become a manager.