Javascript find the Area of a Trapezoid plus don't allow the user to enter non numerical values -
i working basic javascript programme calculate area of trapezoid given variable names , formula area of trapezoid have figured out mostly. part having problem making re-prompts user variable if come in value not number. have tried next alert instead of prompt:
while (isnan(variablename)==true); { variablename = prompt("please come in numerical value"); }
this nil run through loop regardless of if isnan or not. next have far:
var toplen = number(prompt("enter number top length of trapezoid")); var botlen = number(prompt("enter number bottom length of trapezoid")); var trapheight = number(prompt("enter number height of trapezoid")); var traparea = ((.5*trapheight)*(toplen+botlen)); document.write("the area of trapezoid tip length of " + toplen + ", bottom length of " + botlen + " , height of " + trapheight + " " + traparea +".");
please maintain in mind cannot utilize , functions, except isnan() have not been taught them yet.
you have 2 pieces need:
a loop maintain requesting value until valid number a way convert string number, such isnan() can used see if string represented number.you need combine them: convert string prompt number before testing it.
javascript
No comments:
Post a Comment