Command Palette

Search for a command to run...

Hectal
Phase 1: Values, Types and Variables
JavaScript · Exercise 5 of 5 Previous
Intermediate

Fix a broken calculator

This calculator adds the two boxes when you press Add. Right now 2 and 3 give 23. Fix it so it adds numbers: 2 and 3 must show 5, and 1.5 and 2.25 must show 3.75.

If either box is empty, blank, or not a number (like abc), show exactly Please enter two numbers instead.

Remember: input.value is always a string, and Number("") is 0, not NaN.

What Check tests

  1. 2 + 3 shows 5
  2. 1.5 + 2.25 shows 3.75
  3. Spaces around a number are fine: -2 + 7 shows 5
  4. abc shows the error message
  5. An empty box shows the error message
  6. A blank box (only spaces) shows the error message

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.