if statements Flashcards
What are the first 4 characters of an if statement?
if (
What character ends the first line of an if statement?
{
What is the last line of an if statement?
}
if (city = “Las Vegas”) {
In the above statement, what character is incorrect?
It should be ===
if (firstName === “John”) {
Complete the if statement. If the condition is true, display an alert that says, “Hi, John”.
alert(“Hi, John”);
}
Code the first line of an if statement that tests whether one variable has the same value as another.
if (firstName === nickname) {
Code the first line of an if statement that tests whether a variable has the value of a particular string.
if (gender === “female”) {
if (x === y) {
Complete the statement. If the condition is true, display a box that asks the user a question. Assign the answer to a variable that hasn’t been declared beforehand.
var answer = prompt("What is z?"); }
Code an if statement that tests whether pCode is “10010”. If so, assign to the variable city the string “New York”. city has already been declared
if (pCode === “10010”) {
city = “New York”;
}
Code an if statement. Test whether a variable has a particular numerical value. If so, assign a new value to that variable, as in x = 1;
if (pets === 1) {
pets = 2;
}