Write code practice problems:
As many of you have found out directly, the problem with this competency is that if you look at a question and then at the answer, it makes perfect sense until you are confronted with a new problem and a blank piece of paper. That is because it is a process, and not just an end product. You need to know how to build with the tools you have, what can change and what must stay the same. To this end, there is not substitute to working through the problems first on your own, and then with others looking over your shoulder and helping you with the process if/when you make a wrong turn. We have been doing that in class. Try to find other students who can work with you outside of class. See me if you need help making that connection.
Write a javascript program to get scores from a user until a score under 5 is entered. If the score is over 90, print “excellent” and get this student’s name. If the score is in the 80s, print “good”. When you exit the loop, print out the highest odd score in the 80s. Print the average of all scores less than 90.
English:
Get a score
While the score is over 5
if the score is over 90
print excellent
get the student’s name
If the score is under 90
Sum it
count it
If the score is in the 80s
Print “good”
If the score is odd
If the score is the highest so far
Set this score to the new highest
Get the next score
Print the highest odd score in the 80s
Print the average of all scores less than 90 (sum/count)
JavaScript:
var high =sum=count = 0;
testscore = prompt(“enter the first test score”,””);
testscore = parseInt(testscore);
while (testscore >5 )
{
if (testscore>90)
{
document.write(“tExcellent” + “<p>”);
name = prompt(“what is this persons name?”,””);
}
if ((testscore > 90 )
{
sum = sum + testscore;
count = count + 1;
}
if ((testscore < 90 && (testscore>79))
{
document.write(“good” + “<p>”);
if (testscore%2 > 0)
{
if (testscore>high)
{
high = testscore;
}
}
}
testscore = prompt(“enter the next test score or 0 to exit”,””);
testscore = parseInt(testscore);
}
document.write(“high odd in 80s is ” + high + “<p>”);
document.write(“avg under 90s is ” + sum/count + “<p>”);