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

Lucas Guimarães
seal-mask
.a{fill-rule:evenodd;}techdegree
Lucas Guimarães
Front End Web Development Techdegree Student 3,900 Points

My code has more var and doc.write than the teacher`s code. Do you think any company would be satisfied with my code?

This is my code. I wish I could make more sample for everyone. My afraid is to make other developers confused when they start to do some maintenance.

alert("Let's do some math!");

var numberOne = prompt("Insert any number"); numberOne = parseFloat(numberOne); var numberTwo = prompt("Insert any number"); numberTwo = parseFloat(numberTwo);

alert("You are done!");

var title = "<h1>Math with the numbers " + numberOne + " and " + numberTwo + ".</h1>"; document.write(title);

var some = numberOne + numberTwo; var messageSome = numberOne + " + " + numberTwo + " = " + some;

var multi = numberOne * numberTwo; var messageMulti = numberOne + " * " + numberTwo + " = " + multi;

var div = numberOne / numberTwo; var messageDiv = numberOne + " / " + numberTwo + " = " + div;

var minus = numberOne - numberTwo; var messageMinus = numberOne + " - " + numberTwo + " = " + minus;

var finalResult = "<h3>" + messageSome + "<br>" + messageMulti + "<br>" + messageDiv + "<br>" + messageMinus + "</h3>";

document.write(finalResult);

Thanks

Kevin Gates
Kevin Gates
15,053 Points

I'm using the Markdown Cheatsheet to make your code more readable:

alert("Let's do some math!");

var numberOne = prompt("Insert any number");
numberOne = parseFloat(numberOne);
var numberTwo = prompt("Insert any number");
numberTwo = parseFloat(numberTwo);

alert("You are done!");

var title = "<h1>Math with the numbers " + numberOne + " and " + numberTwo + ".</h1>"; document.write(title);

var some = numberOne + numberTwo;
var messageSome = numberOne + " + " + numberTwo + " = " + some;

var multi = numberOne * numberTwo;
var messageMulti = numberOne + " * " + numberTwo + " = " + multi;

var div = numberOne / numberTwo;
var messageDiv = numberOne + " / " + numberTwo + " = " + div;

var minus = numberOne - numberTwo; var messageMinus = numberOne + " - " + numberTwo + " = " + minus;

var finalResult = "<h3>" + messageSome + "<br>" + messageMulti + "<br>" + messageDiv + "<br>" + messageMinus + "</h3>";

document.write(finalResult);

1 Answer

Kevin Gates
Kevin Gates
15,053 Points

To answer your question about would a company be happy with your code: in all honesty, you still have some learning to do to be "full-time" ready, but don't give up! Additionally, you may want to double check your spelling and vocabulary as the word you were looking for was "sum", not "some". Again, don't worry about the simple mistakes. You'll continue to improve, especially here on Treehouse.

You are making good progress! Keep up on the JavaScript courses and you will learn how you can optimize the code you have above to be clearer, more concise, less risk for bugs, and more.