查看: 884|回复: 5
|
请帮我看看这JAVASCRIPT - 初学者
[复制链接]
|
|
请问以下的CODES,我漏了什么东西导致网页变空白. 还是我写错了方法, 因为很想学JAVASCRIPT就跟朋友借了书看,里面有一个FUNCTIONS的练习题,但我做来做去都不知那里错了, 请各位前辈请教
<script type="text/javascript" language="javascript">
function getGPA(pInput)
{
var returnValue = "";
if (pInput >= 93)
returnValue = "4.0";
else if (pInput < 92.2 && pInput >= 90.9)
returnValue = "3.7";
else if (pInput < 89.9 && pInput >= 87)
returnValue = "3.3";
else if (pInput < 86.9 && pInput >= 83)
returnValue = "3.0";
else if (pInput < 82.9 && pInput >= 80)
returnValue = "2.7";
else if (pInput < 79.9 && pInput >= 77)
returnValue = "2.3";
else if (pInput < 76.9 && pInput >= 70)
returnValue = "2.0";
else if (pInput < 69.9 && pInput >= 60)
returnValue = "1.0";
else if (pInput =< 59.9)
returnValue = "0";
else
return 0;
}</script>
<body>
<script type="text/javascript" language="javascript">
var s1 = getGPA(90);
document.write("<br /> S1 "+ s1);
var s2 = getGPA(88);
document.write("<br /> S2 "+ s2);
var s3 = getGPA(84);
document.write("<br /> S3 "+ s3);
var s4 = getGPA(84);
document.write("<br /> S4 "+ s4);
</script>
[ 本帖最后由 Pool 于 19-11-2007 12:36 PM 编辑 ] |
|
|
|
|
|
|
|
发表于 19-11-2007 03:02 PM
|
显示全部楼层
else if (pInput =< 59.9)
倒转
<= |
|
|
|
|
|
|
|

楼主 |
发表于 20-11-2007 03:00 AM
|
显示全部楼层
谢谢楼上的回复,我该了但它出来的是:
S1 0
S2 undefined
S3 undefined
S4 undefined
我要的结果是
S1 4.0
S2 3.3
S3 3.0
S4 3.0 |
|
|
|
|
|
|
|
发表于 20-11-2007 08:36 AM
|
显示全部楼层
原帖由 Pool 于 20-11-2007 03:00 AM 发表 
谢谢楼上的回复,我该了但它出来的是:
S1 0
S2 undefined
S3 undefined
S4 undefined
我要的结果是
S1 4.0
S2 3.3
S3 3.0
S4 3.0
在function 的最后 才return returnValue;
不然你的function 都没有return 任何的东西出去 |
|
|
|
|
|
|
|
发表于 20-11-2007 09:21 AM
|
显示全部楼层
回复 #3 Pool 的帖子
就如vampcheah所说的,你有没有return 你的returnValue。。哈哈。。。写coding时要注意这种基本的东西哦。。。 |
|
|
|
|
|
|
|

楼主 |
发表于 21-11-2007 02:54 AM
|
显示全部楼层
|
|
|
|
|
|
| |
本周最热论坛帖子
|