Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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 :)