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

zhang tao
zhang tao
2,132 Points

I did it, but in a weird way.Does it mean i donot fully understand the previous lesson?

Here's my code. alert("Let's do some math!"); var nub1 = prompt("type an random number"); var nub1convert = parseFloat(nub1); var nub2 = prompt("type another random number"); var nub2convert = parseFloat(nub2);

var message1 = "<h1>Math with the numbers " + nub1convert + " and " + nub2convert + " </h1>"; var message = nub1convert + " + " + nub2convert + " = " + (nub1convert + nub2convert); var message3 = nub1convert + " * " + nub2convert + " = " + (nub1convert * nub2convert); var message4 = nub1convert + " / " + nub2convert + " = " + (nub1convert / nub2convert); var message5 = nub1convert + " - " + nub2convert + " = " + (nub1convert - nub2convert); document.write(message1); document.write('<br/>'); document.write(message); document.write('<br/>'); document.write(message3); document.write('<br/>'); document.write(message4); document.write('<br/>'); document.write(message5);

2 Answers

Steven Parker
Steven Parker
231,275 Points

What would you say is the "weird" part of this code?

Other than longer variable names and the use of individual variables and output statements for each line, it looks much like the instructor's example. While the other method is a bit more compact, your code should perform identically.

Getting the right result is most of the point of a program, so good job. :+1: Refinements like efficiency will come with practice.

Oh, and when posting code, use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:   Or watch this video on code formatting.

zhang tao
zhang tao
2,132 Points

Thank you for your answer . Taking this course is the first time i try to learn programing. I would feel uncertain if my answer do not match the teacher's. thanks!

Steven Parker
Steven Parker
231,275 Points

Your code will often not match exactly. Since the teacher focuses on illustrating specific lesson points, your own code might sometimes even be more efficient and compact!

zhang tao
zhang tao
2,132 Points

Your explanation is clear and helpful to me. Thanks