input something, output something

ساخت وبلاگ
Hi, i need your help. I'm trying to do something like this

Code:

<script>

 function func()
        {
            var input = document.getElementById('num').value;
            var output = document.getElementById('para');
       
            var a = 60;
           
            if(input <= 10) {
                inputx = a;
                output.innerHTML = "Seems like you have " + input + " POINTS, so you get: " + inputx + " EXP.
            }
           
            else if(input > 10 && input <= 20) {
                inputx = a * 2;
                output.innerHTML = "Seems like you have " + input + " POINTS, so you get: " + inputx + " EXP.
            }
           
            else if(input > 20 && input <= 30) {
                inputx = a * 3;
                output.innerHTML = "Seems like you have " + input + " POINTS, so you get: " + inputx + " EXP.
            }
           
            else if(input > 30 && input <= 40) {
                inputx = a * 4;
                output.innerHTML = "Seems like you have " + input + " POINTS, so you get: " + inputx + " EXP.
            }
           
            else if(input > 40 && input <= 50) {
                inputx = a * 5;
                output.innerHTML = "Seems like you have " + input + " POINTS, so you get: " + inputx + " EXP.
            }
           
            else if(input > 50 && input <= 60) {
                inputx = a * 6;
                output.innerHTML = "Seems like you have " + input + " POINTS, so you get: " + inputx + " EXP.
            }
           
            else if(input > 60 && input <= 70) {
                inputx = a * 7;
                output.innerHTML = "Seems like you have " + input + " POINTS, so you get: " + inputx + " EXP.
            }
           
            else if(input > 70 && input <= 80) {
                inputx = a * 8;
                output.innerHTML = "Seems like you have " + input + " POINTS, so you get: " + inputx + " EXP.
            }
           
            else if(input > 80 && input <= 90) {
                inputx = a * 9;
                output.innerHTML = "Seems like you have " + input + " POINTS, so you get: " + inputx + " EXP.
            }
           
            else if(input > 90 && input <= 100) {
                inputx = a * 10;
                output.innerHTML = "Seems like you have " + input + " POINTS, so you get: " + inputx + " EXP.
            }
    </script>
 
<input type="text" placeholder="enter the number" id="num">
    <button onClick="func()">Calculate</button>
    <p id="para"></p>
 
</body>
</html>

Let me explain. When a user enter some number in the input field and press the calculate button, according some system like this

He get an answer on that output.
If he enter 100, the output should be 600 (60 * 10 because it's between 90 - 100, >90 but <= 100 )
if he enter 150, the output should be 900 (60 * 15)
if he enter 109, the output should be 660 (60 * 11 because it's between 100 - 110)
if he enter 111, the output should be 720 (60 * 12 because it's between 110-120)
My code it is working but isn't best pratice. I must write thousands of lines for each case if user enters a big value. So, i need help doing this in a few lines. Sorry my incredible bad English, i'm such a noob.
CodingForums...
ما را در سایت CodingForums دنبال می کنید

برچسب : نویسنده : codingforums بازدید : 141 تاريخ : دوشنبه 29 خرداد 1396 ساعت: 3:33