...

View Full Version : why my coding is not working? can u help me?



sumidave
12-16-2006, 05:38 AM
THis is the question

Write a compound conditional statement that tests whether a previously declared variable named finalScore is greater than or equal to 90, less than 90 but greater than or equal to 80, less than 80 but greater than or equal to 70, or less than 70. Do not use any logical operators (“and” or “or”). Depending on which condition is satisfied, the code should display an alert box message with an appropriate message (e.g., “Final score is in the 80s” or “Final score is below 70”).

_______________________________________________________________

Here are the coding... did i missed out something... please help me!:( :confused:


<html>
<head>
<title>Question 4</title>

<script type="text/javascript">
<!--
var finalScore,

finalScore=window.prompt( "Enter a final score:",'');

if (finalScore<70)
{
document.writeln(finalscore.Final score is below 70);
}
else if(finalScore<80)
{
document.writeln(finalscore.Final score is in the 70s);
}
if (finalScore<90)
{
document.writeln(finalscore.Final score is in the 80s);
}
else{
document.writeln(finalscore.Final score is over 90);
}
alert(finalscore)
//-->
</script>
</head>
<body>
<p>Click Refresh (or Reload) to run the script again<p>
</body>
</html>

whizard
12-16-2006, 05:40 AM
What problem are you having?

Dan

sumidave
12-16-2006, 05:49 AM
once if i run the source document... the window prompt message should appear and that will allow the users to typed number. but the prompt message has not appear at all...

whizard
12-16-2006, 06:08 AM
This code seems to work:


<html>
<head>
<title>Question 4</title>

<script type="text/javascript">
<!--
var finalScore=window.prompt("Enter a final score:")
var text

if(finalScore < 70)
{
text="Score was less than 70.";
//document.writeln(text);
}
if(finalScore > 69 && finalScore < 80)
{
text="Score was in the 70s";
//document.writeln(text);
}
if(finalScore > 79 && finalScore < 90)
{
text="Score was in the 80s";
//document.writeln(text);
}
if(finalScore > 89 && finalScore < 100)
{
text="Score was in the 90s";
//document.writeln(text);
}
if(finalScore > 99)
{
text="Perfect Score!";
//document.writeln(text);
}

window.alert(text)
//-->
</script>
</head>
<body>
<p>Click Refresh (or Reload) to run the script again<p>
</body>
</html>


It seems to do with the fact that you used elseif statements... don't ask me why..

Also, your statements may not have been specific enough, I.E. a score in the 60s would qualify for ALL the IF statements...

Also, window.alert() seemed to work better than alert()...

HTH
Dan



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum