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
roxas shee
Courses Plus Student 2,445 PointsIs there anyone can check my solution? Not sure is it the best way to code it in this way.
This is my solution!
Hopefully its not too strange. https://w.trhou.se/zms4sdsiz1
2 Answers
Steven Parker
243,266 PointsFor what you've learned so far, it looks pretty good.
One suggestion I'd make at this point is to get in the habit of using indentation to indicate nesting level. It can be very handy for spotting causes of problems later on. For example:
/////////////////////////////// instead of THIS: ///////////////////////////////
}
else {
num2 = prompt("Please type another number");
num2 = parseFloat(num2);
if (isNaN(num2)) {
alert("The value you typed is not a numbe. Reload and try again.");
} else if ( num2 === 0) {
alert("Number 0 can't be divided by zero. Reload and try again.");
}
}
////////////////////////////// you could do THIS: //////////////////////////////
} else {
num2 = prompt("Please type another number");
num2 = parseFloat(num2);
if (isNaN(num2)) {
alert("The value you typed is not a numbe. Reload and try again.");
} else if (num2 === 0) {
alert("Number 0 can't be divided by zero. Reload and try again.");
}
}
roxas shee
Courses Plus Student 2,445 Pointsperfect!! thanks for the tips!!🤩