You should use a radio button to request the user enter either EVEN or ODD and a text box for
a number between 1 and 20. You should check to make sure both the values entered comply
with the previous sentence and if not, you should change them to EVEN and 5.
If the user enters EVEN you should output all the numbers between 1 and what they entered
that are EVEN. Do not output the number 1. You should output the number they entered if it is
EVEN.
If the user enters ODD you should output all the numbers between 1 and what they entered
that are ODD. Do not output the number 1. You should output the number they entered if it is
ODD.
If the user enters 1 for their number between 1 and 20 you should output “There are no even
or odd numbers between 1 and 1. Changing your input to 5.”
1
Expert's answer
2018-06-01T04:54:56-0400
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Even/Odd</title> </head> <body> <input type="radio" name="type" value="even" id="type1" checked><label for="type1">EVEN</label> <input type="radio" name="type" value="odd" id="type2"><label for="type2">ODD</label><br> <label for="max">Please enter valut from 1 to 20:</label><input id="max" type="text" name="max"><br> <input type="button" id = "find" value="Find"><br> <div id="numbers"></div> </body> <script type="text/javascript"> window.onload = function(){ var but = document.getElementById("find"); but.onclick = function(){ var numbers = document.getElementById('numbers'); var type = (document.getElementsByName('type')[0].checked=== true)?2:3; var max = parseInt(document.getElementsByName('max')[0].value); numbers.innerHTML = ""; if(max == 1){ numbers.innerHTML = "There are no even or odd numbers between 1 and 1. Changing your input to 5.<br>"; document.getElementsByName('max')[0].value = "5"; max = 5; } else if(max < 1 || max > 20){ document.getElementsByName('max')[0].value = "5"; max = 5; }
for(;type <= max; type +=2) numbers.innerHTML += type + " ";
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment