意外的令牌if(syntaxerror)

时间:2016-07-03 01:41:17

标签: javascript

我不知道错误在哪里 它给了我意想不到的令牌 我已经做了一切来解决它,但仍然没有希望:

    var sleepCheck = function (numHours)

    if(numHours >= 8) {
        return "You're getting plenty of sleep! Maybe even too much!"
    } 
    else {
        return "Get some more shut eye!";
    }

    sleepCheck(10)
    sleepcheck(5)
    sleepcheck(8)

2 个答案:

答案 0 :(得分:3)

你的功能没有大括号:



var sleepCheck = function (numHours){

    if(numHours >= 8) {
        return "You're getting plenty of sleep! Maybe even too much!"
    } 
    else {
        return "Get some more shut eye!";
    }
};

    console.log(sleepCheck(10));
    console.log(sleepCheck(5));
    console.log(sleepCheck(8));




除此之外,请检查大写:sleepCheck,而不是sleepcheck

答案 1 :(得分:0)

2个错误:
- 没有{}的功能 - sleepCheck写为sleepcheck(最后2次通话)

    <script type="text/javascript">
$(document).ready(function(){
    $('input[type="radio"]').click(function(){
        if($(this).attr("value")=="weekly"){
            $(".box").not(".weekly").hide();
            $(".weekly").show();
        }
        if($(this).attr("value")=="monthly"){
            $(".box").not(".monthly").hide();
            $(".monthly").show();
        }
        if($(this).attr("value")=="annual"){
            $(".box").not(".annual").hide();
            $(".annual").show();
        }
        if($(this).attr("value")=="lifetime"){
            $(".box").not(".lifetime").hide();
            $(".lifetime").show();
        }
     });
    });
</script>

https://jsfiddle.net/hda3bxnr/1/

相关问题