- Mar 26, 2005
- 4,094
- 123
- 106
I find this stuff very difficult to understand..
first, I have to create an array of 9 elements, then I have to populate the array with numbers, and then I have to use a function that searches through the array and reports if number was found. I did all that, but the function never "triggers". It's as if I never wrote that code. What gives?
first, I have to create an array of 9 elements, then I have to populate the array with numbers, and then I have to use a function that searches through the array and reports if number was found. I did all that, but the function never "triggers". It's as if I never wrote that code. What gives?
Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<script type="text/javascript">
/********* GLOBAL VARIABLES *********/
// Enter any global variable in this region
/********* FUNCTIONS *********/
// Enter any functions in this region
function countInRow(array, searchVal)
{
for (i = 0; i < 10; i++)
{
if (boardArray[i] === searchVal)
{
document.write("Match not found in index" + i);
}
else
{
document.write("Match found in index" + i);
}
}
}
/********* MAIN *********/
function main()
{
// this will be the entry point of your program,
// write your main code here
var SIZE = 9;
var boardArray = new Array(SIZE); //give me 9 pieces of memory //literal 9 constant
var BR = "<br />";
var i;
for (i = 0; i < 10; i++)
{
boardArray[i] = prompt("Enter a number for box" + i); //we are populating the array one box at a time
document.write([i]); // to show which numbers we entered in the array
}
var searchVal = prompt("Enter the value you are looking for within the array");
countInRow(boardArray, searchVal);
// This line calls main, don't change it:
}
main();
</script>
</body>
</html>
