Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript The Solution

Nour El-din El-helw
Nour El-din El-helw
8,241 Points

Weird result

When I add num1 and num2 it results in a string for some reason. Here is a snapshot of my workspace https://w.trhou.se/x0d7rxdkaa . also i tried changing

var sum = num1 + num2;
message += num1 + " + " + num2 + " = " + sum;

to

message += num1 + " + " + num2 + " = " + (num1 + num2);

but it still didn't work.

1 Answer

Hi Nour,

On this line:

parseFloat(num1);

You are doing the parse operation but not storing, or doing anything with, the result.

You can see here with the console.log statements, that even after doing parseFloat(), num1 is still a string:

var num1 = prompt("Please, insert a number.");
    console.log("num1 type: ", typeof num1);
parseFloat(num1);
    console.log("num1 type: ", typeof num1);

Two things you could try

Update num1 and num2 variables with the result from parseFloat()

var num1 = prompt("Please, insert a number.");
    console.log("num1 type: ", typeof num1);
num1 = parseFloat(num1);
    console.log("num1 type: ", typeof num1);

var num2 = prompt("Please, inert another number"); 
    console.log("num2 type: ", typeof num1);
num2 = parseFloat(num2);
    console.log("num2 type: ", typeof num1);

Do the parsing on the same line as the sum:

var sum = parseFloat(num1) + parseFloat(num2);
console.log("sum type:", typeof sum);

Hope this helps :)