My problem is, when you type an age, it always says "Invalid Age" w/c falls in the default condition. I dont know how to figure out this. Its my codes. Help me to fix this. Thanks!

<html>
<body>
<script type="text/javascript">

var $age = Number(prompt("Enter Your Age: "));

switch ($age)
{

case ($age>='1' && $age<='8') :
document.write('Paramihan ng Toys!');
break;

case ($age>='9' && $age<='18') :
document.write('Pataasan ng Grades!');
break;

case ($age>='19' && $age<='25') :
document.write('Padamihan ng Syota!');
break;

case ($age>='26' && $age<='35') :
document.write('Pagandahan ng Asawa!');
break;

case ($age>='36' && $age<='45') :
document.write('Palakiha ng Income!');
break;

case ($age>='46' && $age<='55') :
document.write('Padamihan, Pagandahan at Pabataan ng kabit!');
break;

case ($age>='56' && $age<='70') :
document.write('Padamihan ng sakit!');
break;

case ($age>='71') :
document.write('Pabonggahan ng Libing!');
break

default :
document.write("Invalid Age!");
break;
}

</script>
</body>
</html>

I hope you can help me.

Your mistakes,
1) with case you can not write condition
2) ignore using single quotes when comparing numbers
3) $ sign is not applicable to pure javascript. use variables without $ sign

<html>
<body>
<script type="text/javascript">

var age = Number(prompt("Enter Your Age: "));



if(age>=1 && age<=8) {
document.write('Paramihan ng Toys!');
}

else if(age>9 && age<18) {
document.write('Pataasan ng Grades!');
}

else if(age>19 && age<25) {
document.write('Padamihan ng Syota!');
}

else if(age>26 && age<35) {
document.write('Pagandahan ng Asawa!');
}

else if(age>36 && age<45) {
document.write('Palakiha ng Income!');
}

else if(age>46 && age<55) {
document.write('Padamihan, Pagandahan at Pabataan ng kabit!');
}

else if(age>56 && age<70) {
document.write('Padamihan ng sakit!');
}
else if(age>71) {
document.write('Pabonggahan ng Libing!');
}
else {
document.write("Invalid Age!");
}


</script>
</body>
</html>

Your mistakes,
1) with case you can not write condition
2) ignore using single quotes when comparing numbers
3) $ sign is not applicable to pure javascript. use variables without $ sign

<html>
<body>
<script type="text/javascript">

var age = Number(prompt("Enter Your Age: "));



if(age>=1 && age<=8) {
document.write('Paramihan ng Toys!');
}

else if(age>9 && age<18) {
document.write('Pataasan ng Grades!');
}

else if(age>19 && age<25) {
document.write('Padamihan ng Syota!');
}

else if(age>26 && age<35) {
document.write('Pagandahan ng Asawa!');
}

else if(age>36 && age<45) {
document.write('Palakiha ng Income!');
}

else if(age>46 && age<55) {
document.write('Padamihan, Pagandahan at Pabataan ng kabit!');
}

else if(age>56 && age<70) {
document.write('Padamihan ng sakit!');
}
else if(age>71) {
document.write('Pabonggahan ng Libing!');
}
else {
document.write("Invalid Age!");
}


</script>
</body>
</html>

Thanks! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.