More Choices
words.js
password = prompt("What is the password?"); if (password.toLowerCase() == "open sesame"){ alert("Welcome to the cave."); } else{ alert("Incorrect password."); }
booleanValues.js
/*--- THESE WILL WORK: ---*/ if(true && true){ alert("&& [AND] only works if both conditions are true"); } if(true || true){ alert("|| [OR] only works if either condition is true"); } if(true || false){ alert("|| [OR] only works if either condition is true"); } if(!(false)){ alert("! [NOT] false is true"); } /*--- THESE WONT WORK: ---*/ if(true && false){ alert("&& [AND] only works if both conditions are true"); } if(false || false){ alert("|| [OR] only works if either condition is true"); } if(!(true)){ alert("! [NOT] true is false"); }
booleanVariables.js
//my preferences: myPreferredRating = 4; //minimum myPreferredPrice = 10; //maximum //when I ordered an Uber: uberRating = 3; //stars uberPrice = 12; //$ //&& = AND: if(uberRating >= myPreferredRating && uberPrice <= myPreferredPrice){ alert("Awesome! Great price and service."); } else { //|| = OR: if(uberRating >= myPreferredRating || uberPrice <= myPreferredPrice){ alert("One of out two isn't bad I suppose."); //! = NOT: if(!(uberRating >= myPreferredRating)){ alert("I'm not happy with the rating."); } //could have used an 'else' here, but to be safe: if(!(uberPrice <= myPreferredPrice)){ alert("I'm not happy with the price."); } } else { alert("I'm not happy with anything. Looks like I'm walking."); } }
- A ride at Dreamworld requires me to be taller than 150cm, and younger than 70 years of age. My height is 160cm, but my age is 75 years of age. Write a program that checks my height and age, and determines whether I am eligible to ride the ride. To begin your code, set a variable
myHeight
to 160, and set a variablemyAge
to 75. You do not need to provide any feedback if I am ineligible, other than "Sorry you do not meet the conditions for this ride." - Ask me for a username and password. If my username is "CathyF" and my password is "400goldSydney" then your program should say "Authenticated". If not, your program should either say "Incorrect username" or "Incorrect password", or both (if that was the case).
- To craft a stone pickaxe in Minecraft I need 3 cobblestones and 2 sticks. Create two variables to store the number of cobblestones and sticks I have. If I have enough of both, say "pickaxe crafted". If I dont, say "not enough resources".