mercredi 23 juin 2021

how do I put my else/if return on a web page with user prompts for values

I have written the code below. I am asking for a user prompt for the values of day and month and I want to return their star sign based on the values that they submit. I do not know how to get the result of their input displayed on a web page.

So 
user prompt for day
user prompt for month
then I want the starsign returned based on the else/if code. Can anybody help?

Thanks        
var StarSign= 
["Aries","Taurus","Gemini","Cancer","Leo","Virgo","Libra","Scorpio","Sagittarius"
"Capricorn","Aquarius","Pisces"]

function signOftheZodiac(theDay,theMonth){
var theDay=prompt("What is your day of birth");
var theMonth=prompt("What is your month of birth");
if ((theDay>=21 && theMonth=="March") || (theDay<=19 && theMonth=="April")){
return StarSign[0];

}else if ((theDay>=20 && theMonth=="April")||(theDay<=20 && theMonth=="May")){
    return StarSign[1];

}else if ((theDay>=21 && theMonth=="May")||(theDay<=20 && theMonth=="June")){
    return StarSign[2];

}else if((theDay>=21 && theMonth=="June") ||(theDay<=22 && theMonth=="July")){
return StarSign[3]

}else if((theDay>=23 && theMonth=="July")||(theDay<=22 && theMonth=="August")){
return StarSign[4]

}else if((theDay>=23 && theMonth=="August")||(theDay<=22 && theMonth=="September")){
return StarSign[5]

}else if((theDay>=23 && theMonth=="September")||(theDay<=22 && theMonth=="October")){
return StarSign[6]

}else if((theDay>=23 && theMonth=="October")||(theDay<=21 && theMonth=="November")){
return StarSign[7]

}else if((theDay>=22 && theMonth=="November")||(theDay<=21 && theMonth=="December")){
return StarSign[8]

}else if((theDay>=22 && theMonth=="December")||(theDay<=19 && theMonth=="January")){
return StarSign[9]

}else if((theDay>=20 && theMonth=="January")||(theDay<=18 && theMonth=="February")){
return StarSign[10]

}else if((theDay>=19 && theMonth=="February")||(theDay<=20 && theMonth=="March")){
result= StarSign[11]

}

var h1=document.createElement("h1")
var textAnswer=document.createTextNode("Your Star sign is")
h1.setAttribute("id","signOftheZodiac");
h1.appendChild(textAnswer);
document.getElementById("flex-child").appendChild(h1)
}
function reset(){
document.getElementById("signOftheZodiac").remove();
}

Aucun commentaire:

Enregistrer un commentaire