0
0
Javascriptprogramming~15 mins

Comparison operators in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
Comparison Operators in JavaScript
📖 Scenario: You are creating a simple program to compare ages of two friends to see who is older or if they are the same age.
🎯 Goal: Build a JavaScript program that stores two ages, compares them using comparison operators, and prints the correct message about who is older or if they are the same age.
📋 What You'll Learn
Create two variables with exact names and values for ages
Create a variable to hold the age difference
Use comparison operators to check which age is greater or if they are equal
Print the correct message based on the comparison
💡 Why This Matters
🌍 Real World
Comparing values is common in apps like age verification, sorting lists, or decision making.
💼 Career
Understanding comparison operators and conditional logic is essential for any programming job.
Progress0 / 4 steps
1
Create age variables
Create two variables called ageAlice and ageBob with the exact values 25 and 30 respectively.
Javascript
Need a hint?

Use const to create variables and assign the numbers 25 and 30.

2
Calculate age difference
Create a variable called ageDifference that stores the result of ageBob - ageAlice.
Javascript
Need a hint?

Subtract ageAlice from ageBob and store it in ageDifference.

3
Compare ages using comparison operators
Use if, else if, and else statements with comparison operators >, <, and === to check if ageAlice is greater than, less than, or equal to ageBob. Inside each block, assign a message string to a variable called result describing who is older or if they are the same age.
Javascript
Need a hint?

Use if to check if Alice is older, else if to check if Bob is older, and else for when ages are equal.

4
Print the result
Write a console.log statement to print the value of the variable result.
Javascript
Need a hint?

Use console.log(result); to show the message in the console.