/    Sign up×
Community /Pin to ProfileBookmark

Using an array to list songs and song title:

There is two parts to this exercise and I’m having difficulty on getting the first one to work. Any advice or tips would be much appreciated. Here is the code:

<html>

<head>

<title>Project 2-6</title>

</head>

<body>

<font color =”blue”><h1>Project 2-6</h1><hr>

<script type =”text/javascript”>

<!– HIDE FROM INCOMPATIBLE BROWSERS
//STOP HIDING FROM INCOMPATIBLE BROWSERS –>

//array is named songs and list a song from each year starting
//with 1990 and ending with 1999.

var song = new array [10]
songs [0] = “Holy Water”;
songs [1] = “Somebody, Somewhere”;
songs [2] = “Lahaina Aloha”;
songs [3] = “I”ll be Thinking of You”;
songs [4] = “You Give Love A Bad Name”;
songs [5] = “War”;
songs [6] = “Nothing Else Matters”;
songs [7] = “Flush”;
songs [8] = “Bag Full Of Thoughts”;
songs [9] = “The Philosopher’s Stone”;

//trying to display the forementioned array

document.write(“<p>” + songs[0] + “<br />”);
document.write(songs[1] + “<br />”);
document.write(songs[2] + “<br />”);
document.write(songs[3] + “<br />”);
document.write(songs[4] + “<br />”);
document.write(songs[5] + “<br />”);
document.write(songs[6] + “<br />”);
document.write(songs[7] + “<br />”);
document.write(songs[8] + “<br />”);
document.write(songs[9] + “</p>”);

</script>

</body>
</html>

to post a comment
JavaScript

13 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERSep 17.2006 — Other than moving the line

//STOP HIDING FROM INCOMPATIBLE BROWSERS -->

to just before the final </script>, what is your problem?

What is the program doing or not doing that you don't or do want it to do?
Copy linkTweet thisAlerts:
@duff2481authorSep 17.2006 — It does not show the actual song names that I have stored in the array. The only thing that shows on the page is my project title.
Copy linkTweet thisAlerts:
@duff2481authorSep 17.2006 — Okay, here is my new code. What I need to do is make an array of 10 elements of my songs from the 1990s. Then display that information out to a webpage. I am not getting anything to display other than my title shows up just fine. Can someone coach me through my issue(s)?? Just need some help to get crackin here...

This is my new code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3.org//TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>

<head>

<title>Project 2-6</title>

</head>

<body>

<font color ="blue"><h1>Project 2-6</h1><hr>


<script type ="text/javascript">

var songs = new Array (10);

songs[0] = "Holy Water"; // first element
songs[1] = "Somebody, Somewhere"; // second element
songs[2] = "Lahaina Aloha"; // third element
songs[3] = "I"ll be Thinking of You"; // fourth element
songs[4] = "You Give Love A Bad Name"; // fifth element
songs[5] = "War"; // sixth element
songs[6] = "Nothing Else Matters"; // seventh element
songs[7] = "Flush"; // eighth element
songs[8] = "Bag Full Of Thoughts"; // nineth element
songs[9] = "The Philosopher's Stone"; //tenth element


document.write("<p>" + songs[0] + "<br />");
document.write(songs[1] + "<br />");
document.write(songs[2] + "<br />");
document.write(songs[3] + "<br />");
document.write(songs[4] + "<br />");
document.write(songs[5] + "<br />");
document.write(songs[6] + "<br />");
document.write(songs[7] + "<br />");
document.write(songs[8] + "<br />");
document.write(songs[9] + "</p>");



//STOP HIDING FROM INCOMPATIBLE BROWSERS -->

</script>







</body>

</html>
Copy linkTweet thisAlerts:
@Mr_JSep 17.2006 — You have not corrected all the mistakes

In this line you have a double quote in the word I'll, this should be a single quote

songs[3] = "I[B][COLOR=Red]"[/COLOR][/B]ll be Thinking of You"; // fourth element
Copy linkTweet thisAlerts:
@duff2481authorSep 17.2006 — Okay, I have the first part of my problem figured out and working just fine.

Now I need to know who to link two arrays together.

Here is what my problem should look like:

1990 Holy Water


I have both of my arrays built, but i'm not sure how to link them together in the same line with either using the + or ++????

Here is my code now: I know that I have my second array (Nineties) commented out, I will uncomment that when I have an idea of what to put either before or after the document.write( information!


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3.org//TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>

<head>

<title>Project 2-6</title>

</head>

<body>

<font color ="blue"><h1>Project 2-6</h1><hr>


<script type ="text/javascript">

var songs = new Array (10);

songs[0] = "Holy Water"; // first element
songs[1] = "Somebody, Somewhere"; // second element
songs[2] = "Lahaina Aloha"; // third element
songs[3] = "I'll be Thinking of You"; // fourth element
songs[4] = "You Give Love A Bad Name"; // fifth element
songs[5] = "War"; // sixth element
songs[6] = "Nothing Else Matters"; // seventh element
songs[7] = "Flush"; // eighth element
songs[8] = "Bag Full Of Thoughts"; // nineth element
songs[9] = "The Philosopher's Stone"; //tenth element


/*var nineties = new Arrary (10);

nineties[0] = "1990";
nineties[1] = "1991";
nineties[2] = "1992";
nineties[3] = "1993";
nineties[4] = "1994";
nineties[5] = "1995";
nineties[6] = "1996";
nineties[7] = "1997";
nineties[8] = "1998";
nineties[9] = "1999";

document.write("<p>" + nineties[0] +<br />")' */
document.write("<p>" + songs[0] + "<br />");
document.write(songs[1] + "<br />");
document.write(songs[2] + "<br />");
document.write(songs[3] + "<br />");
document.write(songs[4] + "<br />");
document.write(songs[5] + "<br />");
document.write(songs[6] + "<br />");
document.write(songs[7] + "<br />");
document.write(songs[8] + "<br />");
document.write(songs[9] + "</p>");



//STOP HIDING FROM INCOMPATIBLE BROWSERS -->

</script>







</body>

</html>
Copy linkTweet thisAlerts:
@Mr_JSep 17.2006 — I,ve took it off so you can't peek then ?
Copy linkTweet thisAlerts:
@duff2481authorSep 18.2006 — I appreciate the last tip, but i'm a CIS major and this is my first java programming class so I don't want anything that is not my own work and that is in PHP.

If someone would be able to help me make adjustments and or give me pointers as to what needs to be done, that would be much appreciated.

Here is the code. What i'm trying to do is concatenate the nineties array and the songs array so that it looks like this:

1990 Holy Water


Here is my code that I'm using and the way i have my operator setup for combining is not working! Any tips or hints is much appreciated

Thanks



Here is the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3.org//TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>

<head>

<title>Project 2-6</title>

</head>

<body>

<font color ="blue"><h1>Project 2-6</h1><hr>


<script type ="text/javascript">

var songs = new Array (10);

songs[0] = "Holy Water"; // first element
songs[1] = "Somebody, Somewhere"; // second element

songs[2] = "Lahaina Aloha"; // third element

songs[3] = "I'll be Thinking of You"; // fourth element

songs[4] = "You Give Love A Bad Name"; // fifth element

songs[5] = "War"; // sixth element

songs[6] = "Nothing Else Matters"; // seventh element

songs[7] = "Flush"; // eighth element

songs[8] = "Bag Full Of Thoughts"; // nineth element

songs[9] = "The Philosopher's Stone"; //tenth element

var nineties = new Arrary (10);

nineties[0] = "1990";
nineties[1] = "1991";
nineties[2] = "1992";
nineties[3] = "1993";
nineties[4] = "1994";
nineties[5] = "1995";
nineties[6] = "1996";
nineties[7] = "1997";
nineties[8] = "1998";
nineties[9] = "1999";


document.write("<p>" + nineties[0] + songs[0] + "<br />");
document.write(nineties[1] + songs[1] + "<br />");
document.write(nineties[2] + songs[2] + "<br />");
document.write(nineties[3] + songs[3] + "<br />");
document.write(nineties[4] + songs[4] + "<br />");
document.write(nineties[5] + songs[5] + "<br />");
document.write(nineties[6] + songs[6] + "<br />");
document.write(nineties[7] + songs[7] + "<br />");
document.write(nineties[8] + songs[8] + "<br />");
document.write(nineties[9] + songs[9] + "</p>");



//STOP HIDING FROM INCOMPATIBLE BROWSERS -->

</script>







</body>

</html>
Copy linkTweet thisAlerts:
@JMRKERSep 18.2006 — First, the code is HTML and Javascript, not java and not PHP.

Second, alter your spelling of Array in:
[code=php]
var nineties = new Arrary (10);
[/code]

Finally, your program should work now.
Copy linkTweet thisAlerts:
@duff2481authorSep 18.2006 — Wonderful! Program works, just one more thing and this is on the formatting side.

How can I do a space or tab between the year and song title? If you could show me on the first document.write I can fix the rest.

Thanks for all the help!
Copy linkTweet thisAlerts:
@gameguy43Sep 18.2006 — just put a space or tab where you want it inside the quotes...
Copy linkTweet thisAlerts:
@duff2481authorSep 18.2006 — okay, where would the quotes go?


document.write(nineties[1] + songs[1] + "<br />"); //prints the year and song of the second element in each array

Call me retarded but i tried in fron of the plus sign after nineties[1] and also after that, but it wipes the whole thing out if I do that, so i'm not sure where specifically quotes would go.

Thanks
Copy linkTweet thisAlerts:
@Mr_JSep 18.2006 — Try

document.write(nineties[1] +" "+ songs[1] + "<br />");
Copy linkTweet thisAlerts:
@duff2481authorSep 18.2006 — Program FINISHED, thanks for all the input everyone had!


Michael
×

Success!

Help @duff2481 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...