Forum : What is wrong with this code
Brief description  about Online courses   join in Online courses
View abhishek  shukla 's Profile

What is wrong with this code

<FORM NAME = "student">
<INPUT TYPE = Text NAME = marksbox Size = 15>
<INPUT TYPE = Button NAME = "b1" VALUE = "Your Grade" onClick = grade()>
</FORM>


<SCRIPT language ="javascript">
function grade(){
marks = document.student.marksbox.value
if(Number(marks)
Asked by abhishek shukla | Oct 7, 2009 |  Reply now
Replies (4)
View bikash kumar singh 's Profile
<html>
<head>
<script language ="javascript">
function grade(){
marks = document.student.marksbox.value
if(Number(marks))
{
if(marks>=90&&marks<=100) alert("You are a A Grade student");
else if(marks>=80&&marks<=89) alert("You are a B Grade student");
else if(marks>=70&&marks<=79) alert("Your Grade is C");
else if(marks>=60&&marks<=69) alert("Your Grade is D");
else if(marks>=50&&marks<=59) alert("Your Grade is E");
else if(marks>=40&&marks<=49) alert("Your Grade is F");
else alert("Your Grade is G you need to work hard");
}
else alert("kindly enter proper marks between 0 and 100");
}
</script>
</head>
<body>
<form name = "student">
<input type = Text name = marksbox Size = 15>
<input type = Button name = "b1" value = "Your Grade" onclick = grade()>
</form>
</body>
</html>
Oct 8, 2009
View abhishek shukla 's Profile
thanks I corrected the error
Oct 8, 2009
View  's Profile
this is wrong because in last inner test you do else branch in too many case, also
test should be if(marks>=40 && marks<=49) ... repeating "marks"
Oct 7, 2009
View abhishek shukla 's Profile
<SCRIPT language ="javascript">
function grade(){
marks = document.student.marksbox.value
if(Number(marks)){
if(marks>=90&&<=100){
alert("You are a A Grade student")
}
if(marks>=80&&<=89){
alert("You are a B Grade student")
}
if(marks>=70&&<=79){
alert("Your Grade is C")
}
if(marks>=60&&<=69){
alert("Your Grade is D")
}
if(marks>=50&&<=59){
alert("Your Grade is E")
}
if(marks>=40&&<=49){
alert("Your Grade is F")
}
else{
alert("Your Grade is G you need to work hard")
}
}
else{
alert("kindly enter proper marks between 0 and 100")
}

}
</SCRIPT>
Oct 7, 2009