I've been trying to make the following code to output a value based on the number allocated, to a span. I'm not sure why or how I'm going wrong.
function myFunction() {
var league = 1
var shirt = 2
if (league == 1) {
if (shirt == 1) {
document.getElementById("shirt").innerHTML = "Score 70+ Goals = 7,500,000";
} else if (shirt == 2) {
document.getElementById("shirt").innerHTML = "Score 60+ Goals = 6,000,000";
} else if (shirt == 3) {
document.getElementById("shirt").innerHTML = "Score 55+ Goals = 5,500,000";
} else if (shirt == 4) {
document.getElementById("shirt").innerHTML = "Score 50+ Goals = 5,000,000";
} else if (shirt == 5) {
document.getElementById("shirt").innerHTML = "Score 45+ Goals = 4,500,000";
} else if (shirt == 6) {
document.getElementById("shirt").innerHTML = "Score 40+ Goals = 4,000,000";
} else if (shirt == 7) {
document.getElementById("shirt").innerHTML = "Score 35+ Goals = 3,000,000";
}
} else if (league == 2) {
if (shirt == 1) {
document.getElementById("shirt").innerHTML = "Score 70+ Goals = 7,000,000";
} else if (shirt == 2) {
document.getElementById("shirt").innerHTML = "Score 60+ Goals = 5,500,000";
} else if (shirt == 3) {
document.getElementById("shirt").innerHTML = "Score 55+ Goals = 5,000,000";
} else if (shirt == 4) {
document.getElementById("shirt").innerHTML = "Score 50+ Goals = 4,500,000";
} else if (shirt == 5) {
document.getElementById("shirt").innerHTML = "Score 45+ Goals = 4,000,000";
} else if (shirt == 6) {
document.getElementById("shirt").innerHTML = "Score 40+ Goals = 3,500,000";
} else if (shirt == 7) {
document.getElementById("shirt").innerHTML = "Score 35+ Goals = 2,500,000";
}
} else if (league == 3) {
if (shirt == 1) {
document.getElementById("shirt").innerHTML = "Score 70+ Goals = 6,500,000";
} else if (shirt == 2) {
document.getElementById("shirt").innerHTML = "Score 60+ Goals = 5,000,000";
} else if (shirt == 3) {
document.getElementById("shirt").innerHTML = "Score 55+ Goals = 4,500,000";
} else if (shirt == 4) {
document.getElementById("shirt").innerHTML = "Score 50+ Goals = 4,000,000";
} else if (shirt == 5) {
document.getElementById("shirt").innerHTML = "Score 45+ Goals = 3,500,000";
} else if (shirt == 6) {
document.getElementById("shirt").innerHTML = "Score 40+ Goals = 3,000,000";
} else if (shirt == 7) {
document.getElementById("shirt").innerHTML = "Score 35+ Goals = 2,000,000";
}
}
}
<span id="shirt">Placeholder text</span>
myFunctionanywhere?myFunctionin awindow.onloadevent handler or at the end of the script. If you try to call it in the head without wrapping the function the elements may not exist. Do see any errors in console?