I got a task to make the user able to enter a wind strength in m/s, and the application must then show how many watts produced per hour. Example: If the user states 3.7 m/s, it should print that the windmill produces approximately 10 watts per hour. The task is not important for u guys, i just wanted to give context. The problem i have is that the program does not run, but i do not see the problem. Thank you :)
Here is the code:
function myFunction() {
var strength selected = document.getElementById("wind strength").value;
if (strengthselected == 1.6 - 3.3) {
document.getElementById("output value").innerHTML = "The wind turbine produces about 2 watts per hour";
} else if (strengthselected == 3.4 - 5.4) {
document.getElementById("output value").innerHTML = "The wind turbine produces about 10 watts per hour";
} else if (strengthselected == 5.5 - 7.9) {
document.getElementById("output value").innerHTML = "The wind turbine produces about 60 watts per hour";
} else if (strengthselected == 8 - 10.7) {
document.getElementById("output value").innerHTML = "The wind turbine produces about 150 watts per hour";
} else if (strengthselected == 10.8 - 13.8) {
document.getElementById("output value").innerHTML = "The wind turbine produces about 400 watts per hour";
} else if (strengthselected == 13.4 - 17.1) {
document.getElementById("output value").innerHTML = "The wind turbine produces about 50 watts per hour";
} else {
document.getElementById("out value").innerHTML = "The wind turbine produces 0 watts per hour";
}
}
<body>
<input type="number" id="wind strength" placeholder="Enter wind strength in m/s">
<button onclick="myFunction"> Press </button>
<p id="out value"> </p>
</body>
I am new to coding and js in general, so i do not really know about any other options or other ways to go at this problem.
What i am expecting is the code to work and that the words "the wind turbine produces about x watts per hour - depending on what numbers the user submitted in the input element" display on the html document.
` is `out value`, not `output value`.
– I'mAUserNow Mar 17 '23 at 16:16