Basic JS conditionals activity
// Here we ask the user if they eat steak, and store the result (true/false) in a variable.
var eatSteak = confirm("Do you eat steak?");
// If the user eats steak (eatSteak === true) we run the following code block.
if (eatSteak) {
document.write("Here's a steak");
}
// If the above condition isn't met (eatSteak !== true), run the following block of code instead.
else {
document.write("Here's a tofu stir fry!");
}
// Bonus
// Here we ask the user what year they were born, and store their response to a variable.
var birthYear = prompt("What year were you born?");
// If the user was born before 1995, alert "SAKE SAKE SAKE!"
if (birthYear < 1995) {
alert("SAKE SAKE SAKE!");
}
// Else if the user was born after 1995, alert "No Sake for you!"
else if (birthYear > 1995) {
alert("No Sake for you!");
}
// If neither of the previous conditions was true (birthYear === 1995) we alert "You inched by!"
else {
alert("You inched by! Sake Sake Sake!");
}