main.window() or what?
I wrote some JS code, but I can´t anything out. I just goes blank. Is it because I don´t have a main functions for my functions?
<html>
<head><title>JavaScript</title></head>
<body>
<script language="JavaScript" type="text/javascript">
document.write("Redovisning av Inlämningsuppgift 4" + "<br/>");
document.write("Informationssystem 1-30, Malmö Högskola, dec 2010" + "<br/>");
document.write("<br/>");
document.write("Usman Rajab, datorid: CDA08028");
document.write("<br/>");
document.write("<br/>");
document.write("==========================================================" + "<br/>");
document.write("UPPGIFT NR 2" + "<br/>");
document.write("============");
document.write("<br/>");
document.write("<br/>");
var loan = 1000000;
var amoyear = 6000;
for( var answer = 1; amoyear * answer <= loan; answer++)
{
}
document.write("Ett lån på 1000000 kr är betalt efter " + Math.ceil(answer) + " år om amorteringen är 500 kr/mån. ");
document.write("<br/>");
document.write("<br/>");
document.write("==========================================================" + "<br/>");
document.write("UPPGIFT NR 3" + "<br/>");
document.write("============");
document.write("<br/>");
document.write("<br/>");
antalAr(1000000,1000);
antalAr(1500000,500);
function antalAr(lan, amortering)
{
amoyear = amortering * 12;
for( var answer = 1; amoyear * answer <= loan; answer++){}
document.write("Ett lån på " + lan + " kr är betalt efter " + Math.ceil(answer) + "år om amorteringen är på " + amortering +" kr/mån." + "</br>");
}
document.write("<br/>");
document.write("<br/>");
document.write("==========================================================" + "<br/>");
document.write("UPPGIFT NR 4" + "<br/>");
document.write("============");
document.write("<br/>");
document.write("<br/>");
for(var i = 1000; i<= 3000; i+=1000)
{
antalAr(1200000,i);
}
document.write("<br/>");
document.write("<br/>");
document.write("==========================================================" + "<br/>");
document.write("UPPGIFT NR 5" + "<br/>");
document.write("============");
document.write("<br/>");
document.write("<br/>");
function Calc(){
for(int i=-1; i<13; i++)
{
alert(monthName(i));
}
}
function monthName(a)
{
if(a == 0)
return 'Januari';
el开发者_运维技巧se if(a == 1)
return 'Februari';
else if(a == 2)
return 'Mars';
else if(a == 3)
return 'April';
else if(a == 4)
return 'Maj';
else if(a == 5)
return 'Juni';
else if(a == 6)
return 'Juli';
else if(a == 7)
return 'Augusti';
else if(a == 8)
return 'September';
else if(a == 9)
return 'Oktober';
else if(a == 10)
return 'November';
else if(a == 11)
return 'December';
else
return 'undefined';
}
</script>
</body>
</html>
Test to see if any JavaScript errors are occurring. In some browsers, once a JavaScript error takes place, script execution stops. In fact, I see some errors just by inspecting your code (you call antalAr
before it has been declared)
Edit:
In IE, the for(int i=-1; i<13; i++)
line is where the first error occurs. (int
is not valid in JavaScript). Replacing int
with var
allows the script to run on my machine.
I'd recommend using IE with script debugging enabled or Firebug during any JavaScript development.
精彩评论