Red_Dragon
12-07-2009, 11:19 PM
Forgive me if the code is rather bad, I am new to Javascript.
Now what I'm aiming to do is after I have entered the contents of the Array's I then want to query the newly created array/database, based on the track number, Via a seprate function.
However all the values I entered, always come up empty.
No matter how many solutions I tried I can't get the query to work. So I've decided to come to you guys/gals for help.
mainMenu()
function mainMenu()
{
menu = 0;
menu = eval(prompt("Select an Operation to Continue\n ====================\n 1 - Create new Database\n 2 - Query Database\n 3 - Show Report\n Any other to exit"));
switch (menu)
{
case 1:
insert(trackNumber)
break;
case 2:
query(trackNumber)
break;
case 3:
break;
}
}
// Enter the track number
function trackNumber()
{
var theNumber = eval(prompt("Enter Track Number"));
if ((theNumber >= 0) && (theNumber < 100))
{
return theNumber; // Stores the track number for insert(trackNumber)
}
}
// This function will allow the user via the (trackNumber)
// parameter to insert the contents of the database
function insert(trackNumber)
{
// Create new Array's
trackNum = new Array(5)
trackName = new Array(5)
trackArtist = new Array(5)
// For each Track we want to hold the trackNumber(),
// the track name and the track's artist.
for(var i = 0; i < trackNum.length; i++)
{
trackNum[i] = trackNumber()
trackName[i]= prompt("Enter Track Name: " + i)
trackArtist[i] = prompt("Enter Track Artist: " + i)
}
}
// This Function will allow the user to query the database, based on track number.
function query(trackNumber)
{
var trackSearch = trackNumber()
var j = 0;
for(j in query)
{
if (query[j] == trackSearch)
{
alert("Track Number: " + trackSearch + "\nTrack Name: " + trackName[j] + "\nTrack Artist " + trackArtist[j]);
break;
}
else if (query[j] != trackSearch)
{
alert("Track Number: Empty" + "\nTrack Name: Empty" + "\nTrack Artist: Empty");
break;
}
}
}
If someone could please help me by posting some relevant code that would help accomplish this, I would greatly appreciate it, as so far I have been scratching my head puzzled, at how I could solve this.
Now what I'm aiming to do is after I have entered the contents of the Array's I then want to query the newly created array/database, based on the track number, Via a seprate function.
However all the values I entered, always come up empty.
No matter how many solutions I tried I can't get the query to work. So I've decided to come to you guys/gals for help.
mainMenu()
function mainMenu()
{
menu = 0;
menu = eval(prompt("Select an Operation to Continue\n ====================\n 1 - Create new Database\n 2 - Query Database\n 3 - Show Report\n Any other to exit"));
switch (menu)
{
case 1:
insert(trackNumber)
break;
case 2:
query(trackNumber)
break;
case 3:
break;
}
}
// Enter the track number
function trackNumber()
{
var theNumber = eval(prompt("Enter Track Number"));
if ((theNumber >= 0) && (theNumber < 100))
{
return theNumber; // Stores the track number for insert(trackNumber)
}
}
// This function will allow the user via the (trackNumber)
// parameter to insert the contents of the database
function insert(trackNumber)
{
// Create new Array's
trackNum = new Array(5)
trackName = new Array(5)
trackArtist = new Array(5)
// For each Track we want to hold the trackNumber(),
// the track name and the track's artist.
for(var i = 0; i < trackNum.length; i++)
{
trackNum[i] = trackNumber()
trackName[i]= prompt("Enter Track Name: " + i)
trackArtist[i] = prompt("Enter Track Artist: " + i)
}
}
// This Function will allow the user to query the database, based on track number.
function query(trackNumber)
{
var trackSearch = trackNumber()
var j = 0;
for(j in query)
{
if (query[j] == trackSearch)
{
alert("Track Number: " + trackSearch + "\nTrack Name: " + trackName[j] + "\nTrack Artist " + trackArtist[j]);
break;
}
else if (query[j] != trackSearch)
{
alert("Track Number: Empty" + "\nTrack Name: Empty" + "\nTrack Artist: Empty");
break;
}
}
}
If someone could please help me by posting some relevant code that would help accomplish this, I would greatly appreciate it, as so far I have been scratching my head puzzled, at how I could solve this.