# 3.1b - Conditionals

Review

• Yesterday's lesson on conditionals seemed to really stump some people. Perhaps the assignment was too complicated.

• Let's pause for a moment and make sure we understand the structure and syntax of the if-statement, known as a conditional.

Mr. Brash's old Scrimba video on if-statements

I can teach it to you, but I can't understand it for you.

• Computer programmers must be good at independent learning. Collaboration is an amazing tool but only you can understand what is placed in front of you.

• Do not expect to understand or get it right the first time. Don't use 2:40pm as your deadline and rush through it.

• When an example is given - mimic it. There are standards and ways of writing that are easier to read.

• When you are given a problem that has a multi-step solution, write out the steps. The number guessing game does not have difficult steps but several of you skipped some.

• Have code you thought should work but now you're totally stuck? Make a copy for safe-keeping and start over.

• Look up examples, do the leg work, and don't just copy & paste!

// Single if

if (thisConditionIsTrue) {

// Do whatever is in here

}

// If with else

if (thisConditionIsTrue) {

// Do this

} else {

// Default case

}

// Single if

if (thisConditionIsTrue) {

// Do this

} else if (thisOtherCond) {

// Do this

} else {

// Default case

}

// Example

if (myValue < 0) {

console.log("Negative");

myValue = myValue * -1;

console.log("Positive.");

}

//Example

if (lastName == "Gates") {

console.log("Hey, Bill.");

} else {

console.log("Hey, you.");

}

// Example

if (myNumber < 0) {

console.log("Negative");

} else if (myNumber > 0) {

console.log("Positive");

} else {

// Only other option

console.log("It is zero");

}