繁体   English   中英

信用计算器不起作用

[英]Credit Calculator Not Working

我在课堂上创建了一个基本的学分计算器,并且我一直坚持为什么不调用我的函数。 我添加了一个警报,以查看它是否甚至可以使它进入功能,并且它无法正常工作……我确定它有点小,但是在盯着屏幕看了几个小时之后,我的教授却无法看到为什么不起作用。 我可以帮忙。

<!doctype html>
<html lang="en">
<head>
<title>Credit Score Grant or Deny</title>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<!-- jQuery library -->
<script 
src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> 
</script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"</script>
<script src="separate.js"></script>

<script>
$(document).ready(function() {

   $("#creditcalc").click( function() {
        alert ("YOLO")
       var input = $("#creditscore").val();
       if (isNaN(input))
            $("#output").html ("Please enter a valid 
             number!")

            else if (parseFloat (input) > 850 || parseFloat 
            (input) < 350) 
            $("#output").html ("Please enter a valid credit 
            score between 350 and 850!")

            else if (parseFloat (input) >= 780 && parseFloat 
            (input) <= 850)
            $("#output").html ("We will grant you a loan at a 
            5% interest rate with your credit score of " + 
            (input))

            else if (parseFloat (input) >= 720 && parseFloat 
            (input) <= 779)
            $("#output").html ("We will grant you a loan at a 
            7% interest rate with your credit score of " + 
            (input))

            else if (parseFloat (input) >= 680 && parseFloat 
            (input) <= 719)
            $("#output").html ("We will grant you a loan at a 
            10% interest rate with your credit score of " + 
            (input))

            else if (parseFloat (input) >= 620 && parseFloat 
            (input) <= 679)
            $("#output").html ("We will grant you a loan at a 
            15% interest rate with your credit score of " + 
            (input))

            else if (parseFloat (input) >= 560 && parseFloat 
            (input) <= 619)
            $("#output").html ("We will grant you a loan at a 
            24% interest rate with your credit score of " + 
            (input))

            else
            $("#output").html ("You are denied. We cannot 
            loan you the money with your low credit score of 
            " + (input) + " at this time. Please work on 
            improving your score.")

   });      
});

</script>

 </head>

<body>

 <center><h2>Credit Score Determination</h2> </center>
<form>
    <center><p>Please enter your credit score and we will let 
 you know if we will grant you a loan and what rate you 
 qualify at!</p></center> 
<br/>
<center><input type="text" id="creditscore"></center>
<br/>
<center><input type="button" id="creditcalc" value="Click 
here to see if you qualify!"></center>
</form>
<br/>
<center><p id="output">I will let you know if your credit 
score qualifies you after you enter a number and click the 
 button!</p></center>

 </body>
 </html>

当使用isNaN作为input的值或textarea始终为String时,需要首先使用parseIntinput的值转换为数字。

主要问题是您的字符串跨越多行,这是语法错误。 您必须将它们与+串联在一起,或者将它们保持在一行上。

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <center><h2>Credit Score Determination</h2> </center> <form> <center><p>Please enter your credit score and we will let you know if we will grant you a loan and what rate you qualify at!</p></center> <br/> <center><input type="text" id="creditscore"></center> <br/> <center><input type="button" id="creditcalc" value="Click here to see if you qualify!"></center> </form> <br/> <center><p id="output">I will let you know if your credit score qualifies you after you enter a number and click the button!</p></center> <script> $(document).ready(function() { $("#creditcalc").click( function() { alert ("YOLO") var input = $("#creditscore").val(); if (isNaN(parseInt(input))) $("#output").html ("Please enter a valid number!") else if (parseFloat (input) > 850 || parseFloat (input) < 350) $("#output").html ("Please enter a valid credit"+ "score between 350 and 850!") else if (parseFloat (input) >= 780 && parseFloat (input) <= 850) $("#output").html ("We will grant you a loan at a "+ "5% interest rate with your credit score of " + (input)) else if (parseFloat (input) >= 720 && parseFloat (input) <= 779) $("#output").html ("We will grant you a loan at a"+ " 7% interest rate with your credit score of " + (input)) else if (parseFloat (input) >= 680 && parseFloat (input) <= 719) $("#output").html ("We will grant you a loan at a"+ " 10% interest rate with your credit score of " + (input)) else if (parseFloat (input) >= 620 && parseFloat (input) <= 679) $("#output").html ("We will grant you a loan at a"+ " 15% interest rate with your credit score of " + (input)) else if (parseFloat (input) >= 560 && parseFloat (input) <= 619) $("#output").html ("We will grant you a loan at a "+ "24% interest rate with your credit score of " + (input)) else $("#output").html ("You are denied. We cannot "+ "loan you the money with your low credit score of " + (input) + " at this time. Please work on "+ "improving your score.") }); }); </script> 

您的字符串必须在它们开始的同一行结束。 (您可以将一串字符串固定在一起,但不能像您一样将字符串保持打开状态。)摆脱字符串中间的换行符,或执行类似的操作

        $("#output").html ("We will grant you a loan at a " + 
        "24% interest rate with your credit score of " + 
        (input))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM