JavaScript Practice exercises - More Variables

I can’t figure out what I’m doing wrong with my script below. I expected 25 - 19 to be calculated in my script, but it keeps coming up as ‘0’. Can someone please clarify for me what I’m doing wrong?

1 Like

by “default” a prompt input will be of type string. You can see this when calling a after your input. it will return the value inside " ". In order to make your input a number, you can use parseInt() or parseFloat(). Int will make your input a number without decimals, Float a number with decimals.

Try this code:

var num1 = parseInt(prompt());
var num2 = parseInt(prompt());
console.log(num1 - num2);

Thank you so much, that was very helpful.

1 Like

You are very welcome. If you have any questions, please reach out any time. If I can, I will always be happy to help you out.