I am pretty new to Javascript and I am trying to update the HTML list below to display certain values depending on the dropdown value I select. However, when I change the dropdown options, the list is not updating with the correct dynamic values. I tried checking the console log but no errors are displaying either.
Any tips on how I can get this working? I would prefer to stick with using vanilla Javascript for now since I am still trying to learn it.
let sel = document.getElementById("num-of-servings");
function servingSize(sel) {
selValue = sel.options[sel.selectedIndex].value;
selText = sel.options[sel.selectedIndex].text;
if (sel === "first") {
document.getElementById("first-ingredient").innerHTML = (1 * selText) + " pounds of beef";
document.getElementById("second-ingredient").innerHTML = (1 * selText) + " teaspoons of salt";
document.getElementById("third-ingredient").innerHTML = (1 * selText) + " teaspoons of pepper";
} else if (sel === "second") {
document.getElementById("first-ingredient").innerHTML = (1 * selText) + " pounds of beef";
document.getElementById("second-ingredient").innerHTML = (1 * selText) + " teaspoons of salt";
document.getElementById("third-ingredient").innerHTML = (1 * selText) + " teaspoons of pepper";
} else if (sel === "third") {
document.getElementById("first-ingredient").innerHTML = (1 * selText) + " pounds of beef";
document.getElementById("second-ingredient").innerHTML = (1 * selText) + " teaspoons of salt";
document.getElementById("third-ingredient").innerHTML = (1 * selText) + " teaspoons of pepper";
} else if (sel === "fourth") {
document.getElementById("first-ingredient").innerHTML = (1 * selText) + " pounds of beef";
document.getElementById("second-ingredient").innerHTML = (1 * selText) + " teaspoons of salt";
document.getElementById("third-ingredient").innerHTML = (1 * selText) + " teaspoons of pepper";
}
}
<select name="1" id="num-of-servings" onchange="servingSize(this)">
<option value="first">4</option>
<option value="second">6</option>
<option value="third">8</option>
<option value="fourth">12</option>
</select>
<ul>
<li id="first-ingredient">1 pound of beef</li>
<li id="second-ingredient">1 teaspoon of salt</li>
<li id="third-ingredient">1 teaspoon of pepper</li>
</ul>