First off, I am not asking anyone to do my homework :P The point of this was to write a simple webpage to become familiar with javascript. It generates and displays random cards from a folder called 'cards'. I completed that part. However, when I submitted it to the teacher he sent me back this screenshot with the subject line "any ideas?"
http://i38.tinypic.com/2wr3e2p.jpg
I have tested this page on several machines and it works in every browser. I have no idea why it just prints the code to the page when he runs it. Any thoughts? (I'm assuming he would javascript enabled, especially since everyone in my class is submitting this program).
Edit: here's the code, sorry but I included everything just to clear any questions
<!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>Aaron's Gamble Page!</title>
<style type="text/css">
* { padding: 0; margin: 0; }
body
{
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
background: #48454C;
}
#wrapper
{
margin: 0 auto;
width: 365px;
}
#header
{
color: #333;
width: 365px;
padding: 10px;
margin: 10px 0px 0px 0px;
background: #A29EA2;
}
#centercolumn
{
color: #333;
padding: 10px;
width: 365px;
background: #DFE0DB;
}
#footer
{
width: 365px;
clear: both;
color: #333;
background: #A29EA2;
padding: 10px;
}
</style>
<script type="text/javascript" charset="utf-8">
// this page created by Aaron Albin
// creation date: October 17, 2009
var score = 0;
function generateCards()
{
var i, randType, randSuite;
var type = new Array("2", "3","4","5","6","7","8","9","t","j","q","k","a");
var suite = new Array("c","d","s", "h");
var cards = new Array(5);
for (i = 0; i < cards.length; i++)
{
cards[i] = setRandomCard(type, suite, cards);
document.write('<img src = "'+cards[i]+'">');
}
}
function setRandomCard(type, suite, cards)
{
var randType, randSuite;
var filePath = "file://C:/cards/";
var fileExt = ".gif";
do
{
randType = Math.floor(Math.random() * type.length);
randSuite = Math.floor(Math.random() * suite.length);
}
while(checkDuplicate(randType, randSuite, filePath, fileExt, type, suite, cards));
addScore(type, randType);
return filePath + type[randType] + suite[randSuite] + fileExt;
}
function checkDuplicate(randType, randSuite, filePath, fileExt, type, suite, cards)
{
var j;
for (j = 0; j < cards.length; j++)
{
if (cards[j] == filePath + type[randType] + suite[randSuite] + fileExt)
{
return true;
}
}
return false;
}
function addScore(type, randType)
{
switch(type[randType])
{
case "2":
score += 2;
break;
case "3":
score += 3;
break;
case "4":
score += 4;
break;
case "5":
score += 5;
break;
case "6":
score += 6;
break;
case "7":
score += 7;
break;
case "8":
score += 8;
break;
case "9":
score += 9;
break;
case "t":
score += 10;
break;
case "j":
score += 11;
break;
case "q":
score += 12;
break;
case "k":
score += 13;
break;
case "a":
score += 1;
break;
default:
score += 0;
}
}
</script>
</head>
<body>
<div id="wrapper">
<div id="header"></div>
<div id="centercolumn">
<h2>Gamble!</h2>
<br />
<p>Welcome to my gambling page. You have drawn</p><br />
<script type="text/javascript" charset="utf-8">generateCards();</script><br /><br />
<p>The value of this hand is <script type="text/javascript" charset="utf-8">document.write(score);</script>.</p>
<br />
</div>
<div id="footer"></div>
</div>
</body>
</html>