Skip to the content.

Homework

Homework after condition lesson

CSSE JavaScript Fundamentals

Homeworks

Part 1:

Choose one from the three options to make a conditonal statement and if help is needed, use the Format at the bottom of the page.

Option 1: Grade Checker

Example for the grade checker:

“F” if the grade is below 60. “D” if the grade is between 60 and 69. “C” if the grade is between 70 and 79. “B” if the grade is between 80 and 89. “A” if the grade is 90 or above.

Option 2: Weather app

Example for a weather app:

If the weather is sunny, print: “It’s a great day to go outside!” If the weather is rainy, print: “Don’t forget your umbrella!” If the weather is snowy, print: “Stay warm and safe!”

Option 3: Character Health Status

Example for a character health status:

If the health is 0, print: “Your character is dead.” If the health is between 1 and 25, print: “Critical condition! Find a health pack!” If the health is between 26 and 75, print: “Your character is wounded. Be cautious.” If the health is above 75, print: “Your character is healthy and ready for action!”

Part 2:

Make another conditional statement with your idea.

Make any If-Then, If, or Then-If statements with different ideas.

Format:
%%js

let health = 10;

if(health == 0)
    console.log("your character is dead");
else if(health >= 1 && health <=25)
    console.log("critical condition");
else if(health >=26 && health <=75)
    console.log("your character is wounded, be caurious");
else if(health > 75)
    console.log("your character is healthy");

//if u have 1 line of code in an if statment, you dont need curly braces

<IPython.core.display.Javascript object>
%%js
let winCoinFlip = Math.floor(Math.random() * 2) == 1 ? true : false;
let money = 10;


while(true){
    if (winCoinFlip) {
        console.log("you won coin flip");
        money *= 2;
    } else {
        console.log("you lost coin flip");
        money /= 2;
    }
    winCoinFlip = Math.floor(Math.random() * 2) == 1 ? true : false;

    console.log(money);

    if(money > 50){
        console.log("you won")
        break;
    }
    else if(money <= 1){
        console.log("you lost");
        break;
    }
    
}


<IPython.core.display.Javascript object>
After testing any of the options, revise it and make another one from the options.