Home HTML Data Types DOM JavaScript JS Debugging Review Ticket

Hacks

  • Write a JavaScript program that compares two variables, a and b. Log “a is greater” if a is greater than b, “b is greater” if b is greater than a, and “both are equal” if a and b are equal. Make sure to use if statements and console.log
%%js

console.log("Conditional If/Then Statements as well as comparisoms");

// Number 1, a comparison between two of my favorite Sci-fi movies, interstellar and the Martian

let theMartianRating = 8.0;
let InterstellarRating = 8.7;

if (theMartianRating > InterstellarRating) {
    console.log("Martian is a better movie");
} else if (theMartianRating === InterstellarRating) {
    console.log("Both movies are equally rated");
} else {
    console.log("Interstellar's the better movies");
}

// Number 2, a comparison between two of my favorite TV shows, Only Murders in the Building and Stranger Things.

let onlyMurdersIntheBuilding = 8.1;
let strangerThings = 8.7;

if (onlyMurdersIntheBuilding > strangerThings) {
    console.log("Only Murders In The Building is a better show");
} else if (onlyMurdersIntheBuilding === strangerThings) {
    console.log("Both shows are equally rated");
} else {
    console.log("Stranger Things is the better show");
}

// Number 3 a comparisom between barbie and oppenhiemer which were battling fiercly over the summer which was famously known as barbenhiemer
let barbie = 7.1;
let oppenheimer = 8.6;

if (barbie > oppenheimer) {
    console.log("Barbe wins Barbenheimer");
} else if (barbie === oppenheimer) {
    console.log("Both movies are equaly good!");
} else {
    console.log("Oppenheimer wins Barbnheimer");
}

<IPython.core.display.Javascript object>