I'm new to Javascript and am trying to learn by making a little program where you enter your astrological sign, planet, and house to make a little madlibs kind of story. To do this, I put three switch statements in one function.
Not sure if that's too many switch statements but, when I load it on Chrome, sometimes I only get text, sometimes I get text and text2, and sometimes I only get text3.
Does anyone know why this is happening? Do I simply have too many switch statements in one function? I searched online but could not find out how many are allowed in one function.
function tellMeaStory() {
var text;
var text2;
var text3;
var sign = document.getElementById("mySign").value;
var planet = document.getElementById("myPlanet").value;
var house = document.getElementById("myHouse").value;
switch(sign) {
case "Aries", "aries":
text = "red";
break;
case "Taurus", "taurus":
text = "calm";
break;
case "Gemini", "gemini":
text = "quirky";
break;
case "Cancer", "cancer":
text = "moody";
break;
case "Leo", "leo":
text = "hungry";
break;
default:
text = "sign";
}
switch(planet) {
case "Sun", "sun":
text2 = "hero";
break;
case "Moon", "moon":
text2 = "mother";
break;
case "Mercury", "mercury":
text2 = "twin";
break;
case "Venus", "venus":
text2 = "courtesan";
break;
case "Mars", "mars":
text2 = "soldier";
break;
default:
text2 = "planet";
}
switch(house) {
case "one", "One":
text3 = "hole";
break;
case "two", "Two":
text3 = "buffet";
break;
case "three", "Three":
text3 = "database";
break;
case "four", "Four":
text3 = "stomach";
break;
case "five", "Five":
text3 = "wilderness";
break;
default:
text3 = "house";
}
document.getElementById("demo").innerHTML += "You are a " + text + " " + text2 + " in a " + text3;
}
<input id="mySign" type="text" value="Enter your sign">
<input id="myPlanet" type="text" value="Enter your planet">
<input id="myHouse" type="text" value="Enter your house">
<button onclick="tellMeaStory()">Generate</button>
<div id="demo"></div>