I'm trying to get an input from a user and display a score after a button is pushed to a defined area of the page depending on the value they enter.
I'm not sure if IF statements are the most efficient way to do this but I thought I would start here.
I've created a simple page with a text input field and a button.
What i'd like is for users to input any number into the field and upon hitting the button, have their score displayed.
I'm using two functions to accomplish this.
function 1: 'calculate()' will eventually take several numbers and perform a further calculation and display a score. For now, I am attempting to assign the result of the function 'followerScore()' to the variable 'score' and display the value of 'score'.
function calculate() {
var score = followerScore();
document.getElementById('result').innerHTML = "Your score is : " + score;
}
function 2: the code for 'followerScore()'
function followerScore() {
var followerScore = 0;
var followers = document.getElementById('followers').value;
if (followers <= 25, 000){
followerScore = 1;
alert(followerScore);
} else if (25000 < followers <= 44000){
followerScore = 2;
} else if (44000 < followers <= 60000){
followerScore = 3;
} else if (60000 < followers <= 75000){
followerScore = 4;
} else if (75000 < followers <= 100000){
followerScore = 5;
} else if (100000 < followers <= 140000){
followerScore = 6;
} else if (140000 < followers <= 180000){
followerScore = 7;
} else if (180000 < followers <= 225000){
followerScore = 8;
} else if (225000 < followers <= 300000){
followerScore = 9;
} else if (followers > 300000){
followerScore = 10;
} else followerScore = "did you pick a number?";
}
I had hoped when inputting values 123 into my form that on click of the 'calculate' button I would get a score of 1 but instead I'm getting an error that says undefined.
html is as follows:
<body>
<form>
<input type="text" placeholder="Followers" id="followers">
</form>
<input type="submit" value="calculate" onclick="calculate();">
<div>
<p id='result'></p>
</div>
</body>
My questions are as follows: 1. Have I incorrectly declared the variable 'followerScore' or why am I getting a result of undefined? 2. Is using IF ELSE statements the best way to evaluate and return the value or is there a way to use SWITCH statements to evaluate to return these scores or what is considered best practice? I feel as if this would be very cumbersome to do a set of IF ELSE if I were, for example, to break up the ranges more.