I'm creating a 12 days of Christmas javascript program and when I print out the statement it keeps repeating the statement. Can you give me any suggestions on how to fix this and get the program to work correctly?
var day = ["first", "second", "third", "fourth", "fifth", "sixth",
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"];
var song = "";
for (var x = 0; x <= 13; x++) {
song += "On the " + day[x] + " day of Christmas";
song += " my true love gave to me: ";
if (x == 0) {
song += "a partridge in a pear tree."
}
else {
switch (x) {
case 12:
song += ("twelve drummers drumming, ");
case 11:
song += ("eleven pipers piping, ");
case 10:
song += ("ten lords a-leping, ");
case 9:
song += ("nine ladies dancing, ");
case 8:
song += ("eight maids a-milking, ");
case 7:
song += ("seven swans a-swimming, ");
case 6:
song += ("six geese a-laying, ");
case 5:
song += ("five gold rings,");
case 4:
song += ("four calling birds, ");
case 3:
song += ("three french hens, ");
case 2:
song += ("two turtle doves ");
case 1:
song += ("and a partridge in a pear tree.");
break;
}
}
console.log(song);}
question from:https://stackoverflow.com/questions/65943642/switch-function-outputting-out-of-order-and-multiple-times