I'm confused on the if/else if/else


#1

https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/0/4?curriculum_id=506324b3a7dffd00020bf661#


var userChoice = prompt("Do you choose rock, paper, or scissors?")
var computerChoice = Math.random()
console.log(computerChoice)
if(condition1) {
    computerChoice ===


#2

Example 1

if (condition) {
    block of code to be executed if the condition is true
} else { 
    block of code to be executed if the condition is false
}

If the hour is less than 18, create a "Good day" greeting, otherwise "Good evening":

if (hour < 18) {
    greeting = "Good day";
} else {
    greeting = "Good evening";
}

The result of greeting will be:

Good evening

Example 2

if (condition1) {
    block of code to be executed if condition1 is true
} else if (condition2) {
    block of code to be executed if the condition1 is false and condition2 is true
} else {
    block of code to be executed if the condition1 is false and condition2 is false
}

If time is less than 10:00, create a "Good morning" greeting, if not, but time is less than 20:00, create a "Good day" greeting, otherwise a "Good evening":

if (time < 10) {
    greeting = "Good morning";
} else if (time < 20) {
    greeting = "Good day";
} else {
    greeting = "Good evening";
}

The result of greeting will be:

Good evening

Hope it help you. If you have some question, please, provide more information about it.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.