if, else if, and else statements>, <, ===)> means "greater than" and < means "less than."=== is used to check if two values are exactly equal.if statement evaluates a condition; if it's true, the corresponding block of code runs.if or else if conditions are true, the else block runs.1let johnAnimals = 10; 2let billyAnimals = 10;
Compare johnAnimals and billyAnimals using conditional statements. Your program should print:
let johnAnimals = 10; let billyAnimals = 10; if (johnAnimals > billyAnimals) { console.log("John has more animals than Billy."); } else if (johnAnimals < billyAnimals) { console.log("Billy has more animals than John."); } else { console.log("John and Billy have the same amount of animals."); }
johnAnimals and billyAnimals, and assign them numbers.if statement to check if johnAnimals is greater than billyAnimals.
true, we print: "John has more animals than Billy."false, we move to the else if statement to check if billyAnimals is greater than johnAnimals.
true, we print: "Billy has more animals than John."true, we reach the else block and print: "John and Billy have the same amount of animals."1let johnAnimals = 10; 2let billyAnimals = 10; 3 4const result = johnAnimals > billyAnimals 5 ? "John has more animals than Billy."\ : johnAnimals < billyAnimals 6 ? "Billy has more animals than John."\ : "John and Billy have the same amount of animals."; 7 8console.log(result);
result and logs it once.console.log() calls and makes the code easier to read.