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 Introducing the Practice

ricky ebanks
ricky ebanks
1,212 Points

My solution to this practice

let first;
let second;

alert("lets do some math!");

first = prompt ("write a number");
second = prompt ("write another number");

first = parseFloat(first);
second = parseFloat(second);

if ( second === 0 ) {
  alert("The second number is 0. You can't divide by zero. Reload and try again.");
} else if ( isNaN(first) || isNaN(second) ) {
  alert("At least one of the values you typed is not a number. Reload and try again.");
} else {

message ="<h1>math with the numbers " + first + " and " + second + "</h1>";
message += first + " + " + second + " = " + (first + second); 
message += "<br>";
message += first + " * " + second + " = " + (first * second);
message += "<br>";
message += first + " / " + second + " = " + (first / second);
message += "<br>";
message += first + " - " + second + " = " + (first - second);
document.write(message);
}
James Reich
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
James Reich
Front End Web Development Techdegree Graduate 14,854 Points
let first; let second;

alert("lets do some math!");

first = prompt ("write a number"); 
second = prompt ("write another number");

first = parseFloat(first);
second = parseFloat(second);

if ( second === 0 ) { 

alert("The second number is 0. You can't divide by zero. Reload and try again."); 

} else if ( isNaN(first) || isNaN(second) ) { 

alert("At least one of the values you typed is not a number. Reload and try again."); 

} else {

message ="<h1>math with the numbers " + first + " and " + second + "</h1>"; 
message += first + " + " + second + " = " + (first + second); 
message += "<br>"; 
message += first + " * " + second + " = " + (first * second); 
message += "<br>"; 
message += first + " / " + second + " = " + (first / second); 
message += "<br>"; 
message += first + " - " + second + " = " + (first - second); 

document.write(message); 
}

Looks good! Just letting you know, that you can surround your code with 3 backticks ``` at the beginning and end, and it will treat it as code and highlight it accordingly. You can also tell it what language you're using by putting the language right after the first set of backticks for proper syntax highlighting!