If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    Jul 2010
    Member #
    Hi guys, college student here having some trouble with the JavaScript portion of my computer science class. I'm almost done with this week's assignment, but this one problem is giving me fits.

    It asks me to wite a script that uses repetition and a switch structure to print the song 'The Twelve Days of Christmas.'

    I somewhat understand what it is trying to get me to do... something along the lines of, case "1": A partridge in a pear tree. case "2": case "1" + two turtle doves...

    And I also know that I should probably make a variable for each "day".. I just can't wrap my head around the problem as a whole. Please help me. I'm not some lazy student on here begging yall to do my homework, I just can't get help from my professor since the class is being taken in and online format and can't afford a tutor! I've worked hard on this and hate to hit this wall.

    Thanks in advance guys...


  3. #2
    Senior Member paintingtheweb's Avatar
    Join Date
    Jul 2007
    Las Vegas
    Member #
    Something like this maybe?

    var song_str = "";
    for(i = 1; i <= 12; i++){
        case 1:
          song_str += "On the first day of christmas my true love gave to me: A partridge in a pear tree<br />";
        case 2:
          sont_str += "On the second day....";
        case 12:
          song_str += "On the twelfth day.....";
    document.getElementById("songdiv").innerHTML = song_str;

  4. #3
    Join Date
    May 2010
    Member #

    Thanks for the code, I will try it.

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
All times are GMT -6. The time now is 12:12 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: