Skip to content

Latest commit

 

History

History
44 lines (32 loc) · 1.41 KB

if-and-else-if....else.md

File metadata and controls

44 lines (32 loc) · 1.41 KB

🔑 If and Else (if....else)

Let's try creating a simple if and else statement that checks the score.

If the score is more than 80, let's print 'Congratulations!' . Else, print 'It's ok, try harder next round.'

First, we have to initialise the score. You can give the score of 40 or any value that you want to check.

let score = 40;
if (score >= 80){
    console.log("Congratulations!!!");
}
else
    console.log("It's ok, try harder next round.");

🎉 Now, you have created a if and else statement successfully! Try the exercise below!


Exercise

If i'm hungry, I want the application to print "I'm hungry!!!Feed me now!!!!". If i'm not, i want it to print "I'm not hungry".

Want Answer? Press me!
let hungry = false;
if (hungry){	//hungry === true
    console.log("I'm hungry!!!Feed me now!!!!");
}
else
    console.log("I'm not hungry");





◀️ Previous Page : Control Flow : Conditional Statements 🚩 🔓             🏡            ▶️ Next Page : Conditional Statements : Switch and Case 🔑