Practice and reinforce the concepts from Lesson 3
In this activity, you will learn how to use mathematical operators in JavaScript to perform calculations. You'll create calculators for birth year, BMI, age in months, and time conversions using arithmetic operations.
⚠️ Warning DO NOT DELETE the existing files in the template:
- Package files
- Any other files you didn't create
ONLY EDIT the necessary files.
In each exercise below, click the Stackblitz link and familiarize yourself with the interface.
Open in StackBlitzStackBlitz Project
stackblitz-starters-9fnazwom
💡 Tip You can also download the source code template from Stackblitz using the Download Project button if you prefer to use your own IDE.
year and assign the value of this yearage and prompt() a message saying "What is your age?"birthYear and calculate it with: year - agealert(): "Your birth year is " + birthYearExample: If the year is 2021 and your age is 15:

var year = 2021;
var age = +prompt("What is your age?");
var birthYear = year - age;
alert("Your birth year is " + birthYear);
💡 Tip Notice the
+beforeprompt()? This converts the string input into a number so we can do math with it!
Open in StackBlitzStackBlitz Project
stackblitz-starters-pqdgx1kw
BMI (Body Mass Index) helps estimate if your body is at a healthy weight. Learn more about BMI results here.
BMI = weight / (height × height)Math.round() to round the result💡 Tip Remember to use
+prompt()to convert string inputs to numbers! For example:
var weight = +prompt("Enter your weight in kg:");
Expected Results:



Open in StackBlitzStackBlitz Project
stackblitz-starters-e7nq3kbb
How many months have you been alive? Let's calculate that using your age and birth month!
months = (age × 12) + (curMonth - birthMonth)💡 Tip Common Challenge: Getting wrong results?
+ operator: var age = +prompt("What is your age?");Expected Results:




Open in StackBlitzStackBlitz Project
stackblitz-starters-va6znw8y
Let's convert seconds into a readable format showing hours, minutes, and seconds!
hours = totalSeconds / 3600minutes = (totalSeconds % 3600) / 60seconds = totalSeconds % 60Math.round() to round all results💡 Tip Understanding the % (modulo) operator:
% gives you the remainder after division10 % 3 = 1 (because 10 / 3 = 3 remainder 1)Expected Results:


Before submitting, make sure your projects include:
+prompt() for number conversion💡 Tip Common Problems & Solutions:
Getting NaN (Not a Number)?
+prompt() not just prompt()Calculations seem wrong?
Prompts not appearing?
ℹ️ Ready to submit your projects? When you have completed ALL THREE calculator projects:
- Test each calculator with the example values
- Make sure all results match the expected outputs
- Submit your work here:
Submit Your Projects Here
Remember: Test all calculations before submitting!