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 JavaScript Basics (Retired) Working With Numbers Numbers and Strings

Kimberly Dolcin
Kimberly Dolcin
4,369 Points

what is wrong with my code?

alert("Lets do some math!"); var num = prompt("Please type in a number"); var realnum=parseFloat(num); var num2 = prompt("Please type in a number"); var realnum2=parseFloat(num2); var sum = realnum + realnum2; var message = "<h1>Math with the numbers"+ " "+ "realnum" + "and"+ "realnum2</h1>"; document.write(message+ realnum + " " + "+" realnum2 + " " + "=" + sum;

3 Answers

document.write(message+ realnum + " " + "+" realnum2 + " " + "=" + sum;

document.write(message + realnum + " " + "+" + realnum2 + " " + "=" + sum);  
//you are missing a plus before realnum2 and the closing parenthesis for document.write function

// also note that you can add spaces within the quotation marks like so to format the appearance of strings:
// " + " this would yield a space before and after the plus sign
// "+" this would have no spaces before and after
// "+ " this would have one space after.  It will save you from having to insert " " over and over to get that space.

As an aside, it will be much easier for you to trouble shoot your code if you exercise good indentation and spacing. Cheers!

Kimberly Dolcin
Kimberly Dolcin
4,369 Points

omg thank you so much Nick for explaining!

No worries Kimberly! Also as David points out, camel case is really helpful in naming variables! You are writing good code, these little things are what we all go through.

Here is an example of using camel case to name a variable.

var realNum; // camel case 
var realnum; // not using camel case

It helps you to pick out variables in your code much easier and it just improves readability. You are going to see most doing this in the examples of code you see. As with anything, the more you write and read other people's code, the more you will intuitively start doing this. If you think about how we all speak English, I mean I don't really know how to use semicolons, commas, or any of the grammatical necessities. However, because I read books--and much like us all--I can speak English and write it. I think there is this push at times to understand everything and really, it's just about getting comfortable enough to speak the language without knowing all the reasons as to WHY something is happening. In time, holes fill themselves in through necessity or experience.

Cheers!

Kimberly Dolcin
Kimberly Dolcin
4,369 Points

Thanks again Nick! I agree with you 100%. I know if I am not struggling, i am not learning enough so in a way I always try to get to a place where I am struggling since that is a sign of growth! The English language is a great analogy!

David Hargrove
PLUS
David Hargrove
Courses Plus Student 2,044 Points

Please also consider camel case, at least. It will also improve readability. I also notice the way you have posted your code the line endings seem to be using an odd character... are you using an external editor?'

Kimberly Dolcin
Kimberly Dolcin
4,369 Points

hi, thank you for your suggestions and no i use workspaces and when it doesnt work on my browser i try to insert it into codepen

David Hargrove
PLUS
David Hargrove
Courses Plus Student 2,044 Points

Great -- well, as you continue your journey... consider familiarizing yourself with a solid editor. Although I never was much of a Microsoft fan, their recent open source provisions, their acquisition of github, and Windows IOT Core.... I recommend checking out VS Code. It's a really great, free, open source code editor. Also, check out Atom, or... my favorite, Sublime Text.