Okay, so I am just going over some basic programming tenets in JavaScript (I am new to programming, so bear with me please). Below is the code I am having issues with (pay particular attention to the string component of the array).
var name = new Array();
var sales = new Array();
var total = prompt("How many total salesmen does your department employ?");
for(i = 0; i < total; i++)
{
name[i] = prompt("What is his/her (the salesman's) name?");
sales[i] = prompt("How much (in dollars) did he/she sell?");
}
for(j = 0; j < i; j++)
{
document.write(name[j]+" had $"+ sales[j]+" in sales!<br>");
}
As you can see, it's just a simple code to get me familiar with arrays of various types of elements. For some reason, the code returns:
undefined had $100 in sales!
undefined had $2999 in sales!
undefined had $4999 in sales!
undefined had $32342 in sales!
which is exactly what I need, except for the fact that each of the elements within the name array is undefined.
I'm thinking it may be an issue with the document.write function, as i've read that it can be dubious but I still don't know exactly how to get this working properly.
Any help would be greatly appreciated!