Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

ricky ebanks
ricky ebanks
1,122 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
215,940 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.