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

ricky ebanks
ricky ebanks
1,212 Points

My solution to the if else and isNaN practice in Javascript

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);
}
Steven Parker
Steven Parker
231,236 Points

When posting code, use Markdown formatting to preserve the code's appearance. You might also take a look at this video about Posting a Question.