Hi guys,
When I run my code, showProducts() function is called and prints text to the screen fine. But once it enters the for loop in the function, it messes up . I.e. it doesn’t print no more than one line of products. (by the way I’m not bothered about security issues withe logging in as it’s just an assignment).
—————————————CODE———————————
<HTML>
<HEAD> M150 TMAO3 Question 2
<TITLE>SOFASPEND – IN THE BEST POSSIBLE TASTE!</TITLE>
<SCRIPT language=”JavaScript” type=”text/javascript”>
// These are arrays containing customer data
var customerCodes = [‘lt-17’, ‘gw-3’, ‘lg-9’, ‘il-77’, ‘fy-32’];
var customerPasswords = [‘password’, ‘bluesky’, ‘dr45gr6’, ‘onlyme’, ‘lothlorien’];
// These are arrays containing product data
var productCodes = [‘a-23-009’, ‘k-246-07’, ‘d-555-01’, ‘n-87-012’, ‘u-521-08’, ‘t-99-002’];
var productDescriptions = [‘Superslurry electric blender’, ‘Apple – iPod (second-hand)’, ‘CoziNap nylon duvet tog 2’, ‘Headbanger mini hi-fi 20W’, ‘MagiBoot shoe cleaning kit’, ‘The PushmiPulu lawnmower’];
var productPrices = [45, 50, 15, 25, 75, 7, 60];
var productStock = [200, 0, 2, 500, 500, 15];
// These are useful variables
var customerIndex;
/*……………………………………………………………………………..
var bFlag = false;
var start;
while (bFlag == false)
{
start = window.prompt(‘Please enter your unique password.’,”);
checkPassword(start);
};
document.write(‘<BR><BR>Welcome, ‘ + customerCodes[customerIndex] + ‘. Ready to start shopping?<BR>’);
showProducts();
function checkPassword(password)
{
for (var i = 0; i < 5; i++)
{
if (password == customerPasswords[i])
{
customerIndex = i;
bFlag = true;
return;
}
}
}
function showProducts()
{
document.write(‘<BR> Here are the products currently in stock:<BR>’);
document.write(‘Item—Code———Product———————-Price– -Stock<BR>’);
document.write(‘============================================<BR>’);
for (var i = 0; i < 5; i++)
{
document.write(i + ‘—–‘ + productCodes[i] + ‘—-‘ + productDescriptions[i] + ‘—–‘ + productPrices[i] + ‘—-‘ + productStock[i] + ‘<BR’);
}
}
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>