-
I have an been working on this tutorial and it explains how to use variables in an array. well when the variables where not in an array the javascript printed the varibles.but now it will not print anything can some one help with this, I have tried every thing I can think of, even thought it was my local machine settin\gs. I am at a loss.
html>>>
Code:
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>NBA Finals All-Time Scoring Leaders</title>
<link rel="stylesheet" href="js_styles.css" type="text/css"/>
<script src="nba.js" type="text/javascript"></script>
</head>
<body>
<h1>NBA Finals</h1>
<h2>ALL-Time Scoring Leaders</h2>
<script type="text/javascript">
document.write("<p><b>scored</b></p>"+leader1[0]);
</script>
</body>
</html>
the js
Code:
var leader1 = new Array();
leader1[0] = "Rick Barry";//player name
leader1[1] = 10;//number of games
leader1[2] = 138;//two point baskets
leader1[3] = 87;//free throws
leader1[4] = leader1[2] * 2 + leader1[3];//total points
leader1[5] = leader1[4] / leader1[1];//average points
var leader2 = new Array();
leader2[0] = "Micheal Jordan";
leader2[1] = 35;
leader2[2] = 438;
leader2[3] = 258;
leader2[4] = leader2[2] * 2 + leader2[3];
leader2{5] = leader2[4] / leader2[1];
-
Hello.
I saved the code you posted and viewed the oage and I got no errors, the script worked the way you want it to.
Suggestions
1: Check that the nba.js file is in the same directory as the html file. If it isnt, change the src value to match the correct path.
2: Use firefox to test your pages and download a addon called firebug (here)
-
I discovered the error is in the array element... leader2[5]... it contains a curly bracket. thank you for your help.