Solution 1 :

Your prompt inputs (txt and cal) are strings… you need to parse them to integers

let txt = prompt('Please enter your calculation');
let cal = prompt('And the other one');
let orange = parseInt(txt); let apple = parseInt(cal);

alert(orange + apple);

if you also want to add floats, use parseFloat() instead of parseInt()

Problem :

I am learning Javascript and I am trying to make a simple HTML calculator where 2 prompts appear asking for numbers to add. Anytime I execute I get just the 2 numbers added together like 2 + 2 = 22, I did something wrong because I would want the response to be the right answer. Thanks so much!

‘use strict’;

let txt = prompt('Please enter your calculation');
let cal = prompt('And the other one');

let orange = txt;
let apple = cal;

alert(orange + apple);

Comments

Comment posted by Anupam Haldkar

You need to convert into integer or float as they are strings

By

Leave a Reply

Your email address will not be published. Required fields are marked *