开发者

I'm pretty sure I'm suppose this statement

OK, I'm kinda stuck on this one. I'm looking in my book.

I'm thinking I'm supposed to use the if or the else statement with this. When I try to validate it is coming up with 3 errors. Can someone point out hints to what I'm missing?

Thank you. I'm not this far in javascript yet.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" href="js_styles.css" type="text/css" />
<script type="text/javascript">
//<![CDATA[
<!--HIDE FROM INCOMPATIBLE BROWERS
function checkGrade(grade) {
switch(grade) {

    case "A":
        document.write("Your grade is excellent.");
        break;
    case "B":
        document.write("Your grade is good.");
        break;
    case "C":
        document.write("Your grade is fair.");
        break;
    case"D":
        document.write("You are barely passing.");
        break;
    case"F":
        document.write("you failed.");
        break;
    defult:
        document.write("You did not enter a valid letter grade.")
        break;

    }
    }
//STOP HIDING INCOMPATIBLE BROWERS-->
//]]>
</script>
<开发者_开发百科;/head>
<body
<form name ="gradeForm" "action" ="">
<input type="text" name="grade" />
<input type="button" value="CheckGrade" onclick="checkGrade(document.gradeForm.grade.value);" />
</form>
</body>
</html>


You're missing the second > on your body tag, and you have an extra quote before your form's action attribute.

You may also want to put ".toUpperCase()" in this statement so the user can enter "a" or "A".

switch(grade.toUpperCase()) {

With @Matchu's noted fix of "default", I was able to run your code in Internet Explorer, Firefox, and Chrome.

Final version can be seen in this pastie.


Consider deleting the extra set of <!DOCTYPE>, <HTML> and <HEAD> tags. I'm not sure if they're the source of your js errors (you didn't tell us what the errors were) but they certainly aren't helping.

You are missing spaces on case"F" and case"D". They should be case "F" andcase "D"`. This isn't an error per se, but best to keep it consistent.

Your <body> tag is also left unclosed. This is probably the source of your errors.

Edit:

Some more stuff:

<form name ="gradeForm" "action" =""> should be <form name="gradeForm" action="">


Try changing <input type="text" name="grade" /> to <input type="text" id="grade" />

Use name= if you are submitting a form, but id= if you need javascript to id it. It is possible to have several inputs with the same name.

--Dave


Looks good, except for some typos. Note the defult instead of default, for instance, and the unclosed <body start tag.

What do you mean, exactly, when you refer to errors? Are these errors in the Javascript console, or errors running the HTML through a validator? The W3's HTML validator doesn't check Javascript syntax.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜