I’m having problems in the JavaScript I have written. This script is suppose to prompt the user for the weight, from 0 to 126 and then have an alert box pop up descibing the weight they are in.
weight class from to
-------------------------------
Fly 0 112
SuperFly 112 115
Bantam 115 118
SuperBantam 118 122
Feather 122 126
<script type="text/javascript">
var weight = parseInt(prompt("What is your weight?"));
if (weight > 126) {
alert('Please enter a weight lighter than 126');
}
document.writeln('<br/>');
var wArray = String ([fly,superfly,bantam,superbantam,feather]);
function recruit() {
if (0 < weight < 112){
document.writeln('You are in' + wArray[0] +'class!');
}
if (112 < weight < 115){
document.writeln('You are in' + wArray[1] +'class!');
}
if (115 < weight < 118){
document.writeln('You are in' + wArray[2] +'class!');
}
if (118 < weight < 122){
document.writeln('You are in' + wArray[3] +'class!');
}
if (122 < weight 126){
document.writeln('Your weight class is' + wArray[4]);
}
</script>
Change this
to this
All arrays in JavaScript are dynamically typed. There’s no way to create a string array; you just create an array and fill it with strings.
Also,
is not valid. You want