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 trialSarah Caro
2,151 PointsPractice JavaScript Math Solution
If anyone was interested in an alternative solution, here is mine. It isn't super elegant but I'm proud of the lack of concatenation :p
alert("Let's do some math!");
//First user input
var yourNumber = prompt("Pick a number, any number!");
yourNumber = parseInt(yourNumber);
//Second user input
var yourNumberAgain = prompt("Now, another number, any number!");
yourNumberAgain = parseInt(yourNumberAgain);
/*Ok, all strings converted. Now, functions: */
function newNumberAdd (num, num){ var newNumber; newNumber = yourNumber + yourNumberAgain; document.write(newNumber); }
var message = <h1>Math with the numbers ${yourNumber} and ${yourNumberAgain}
;
var addProblem = <br>${yourNumber} + ${yourNumberAgain} =
;
function newNumberSub (num, num){ var newNumber; newNumber = yourNumber - yourNumberAgain; document.write(newNumber); }
var subProblem = <br>${yourNumber} - ${yourNumberAgain} =
;
function newNumberMulti (num, num){ var newNumber; newNumber = yourNumber * yourNumberAgain; document.write(newNumber); }
var multiProblem = <br>${yourNumber} * ${yourNumberAgain} =
;
function newNumberDivi (num, num){ var newNumber; newNumber = yourNumber / yourNumberAgain; document.write(newNumber); }
var diviProblem = <br>${yourNumber} / ${yourNumberAgain} =
;
//Print to website
document.write (message);
document.write (addProblem); newNumberAdd();
document.write (subProblem); newNumberSub();
document.write (multiProblem); newNumberMulti();
document.write(diviProblem); newNumberDivi();
Steven Parker
231,269 PointsSteven Parker
231,269 PointsFor your code to be seen properly, always post using Markdown formatting.