Vous êtes sur la page 1sur 5

# c   



   
2 

1. Here is a simple problem for you to solve using an if else statement. Suppose you must

get a grade of 70 or better to get a passing grade for this class. Write a script that will test

to see if you passed and will display the results in the browser as following:

## - If not display "Sorry, you did not pass."

2. Write a script that contains a function getStatus() that you can pass a grade as a

parameter and have it display a passed or failed condition. Demonstrate the functions by

printing out the pass/fail status for five students. One example of one student could be:

## document.write("Mary - ") + getStatus(94) + document.write("<BR>")

3. Make a final modification to the above script that a letter grade is displayed instead of

## pass or fail. This letter grade should be based on the following:

A is a grade of 90 or greater

## F is any grade below 70

Solutions 1-2:

<HTML>
<SCRIPT language="JavaScript">
<!--
document.write("Congratulations, you passed.")
}
else{
}
}
//-->
</SCRIPT>

<BODY bgcolor="white">

<P>
<SCRIPT language="JavaScript">
<!--
document.write("Mary - ") + getStatus(94) + document.write("<BR>")
document.write("Jim - ") + getStatus(70) + document.write("<BR>")
document.write("Albert - ") + getStatus(65) + document.write("<BR>")
document.write("Carroll - ") + getStatus(88) + document.write("<BR>")
document.write("Francis - ") + getStatus(44) + document.write("<BR>")
//-->
</SCRIPT>

</BODY>
</HTML>
Solution 3:

<HTML>
<SCRIPT language="JavaScript">
<!--
}
}
}
}
}
//-->
</SCRIPT>

<BODY bgcolor="white">

<P>
<SCRIPT language="JavaScript">
<!--

//-->
</SCRIPT>
<HTML>
<SCRIPT language="JavaScript">
<!--
return "A"
}
return "B"
}
return "C"
}
return "F"
}
//-->
</SCRIPT>

<BODY bgcolor="white">

<P>
<SCRIPT language="JavaScript">
<!--
document.write("Mary - " + getStatus(94) + "<BR>")
document.write("Jim - " + getStatus(70) + "<BR>")
document.write("Albert - " + getStatus(65) + "<BR>")
document.write("Carroll - " + getStatus(88) + "<BR>")
document.write("Francis - " + getStatus(44) + "<BR>")
document.write("George - " + getStatus(89) + "<BR>")
document.write("Alice - " + getStatus(90) + "<BR>")
document.write("Sam - " + getStatus(79) + "<BR>")
document.write("Pat - " + getStatus(80) + "<BR>")
document.write("Ray - " + getStatus(100) + "<BR>")
//-->
</SCRIPT>

</BODY>
</HTML>
</BODY>
</HTML>
<HTML>
<SCRIPT language="JavaScript">
<!--
}
}
}
}
document.write(name + " - " + letterGrade + " (" + grade + ")<BR>" )
}
//-->
</SCRIPT>

<BODY bgcolor="white">

<P>
<SCRIPT language="JavaScript">
<!--