JavaScript有参函数的调用

问题遇到的现象和发生背景

一直没有结果

用代码块功能插入代码,请勿粘贴截图
html>
<html>
    <head>
        <meta charset="utf-8">
        <title>实训1title>
    head>
    <body>
        <script type="text/javascript">
            function judge(n){
                if(Boolean(n)){
                    alert("赋值变量的布尔值为:true")
                }
                else{
                    alert("未赋值变量的布尔值为:false")
            }
            var value1,value2=2;
            judge(value1);
            judge(value2);            
        script>
    body>
html>

运行结果及报错内容

在网页中查看错误说是“Unexpected end of input”

我想要达到的结果

用函数完成下图效果

img

函数结尾少了括号了{}

少了个花括号


<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>实训1</title>
    </head>
    <body>
        <script type="text/javascript">
            function judge(n){
                if(Boolean(n)){
                    alert("赋值变量的布尔值为:true")
                }
                else{
                    alert("未赋值变量的布尔值为:false")
                }
            }
            var value1,value2=2;
            judge(value1);
            judge(value2);            
        </script>
    </body>
</html>
 

直接写if(n),不要用函数转换


        function judge(n) {
            if (Boolean(n)) {
                alert("赋值变量的布尔值为:true")
                console.log(n,"98")
            }
            else {
                alert("未赋值变量的布尔值为:false")
                console.log(n,"99")
            }
        }
        var value1, value2 = 2;
        judge(value1);
        judge(value2);  

我试了一下 可以啊 。 value1 是 undefined 转换成 布尔 值是 false 走else 。2的布尔值是true

<script type="text/javascript">
            function judge(n){
                if(Boolean(n)){
                    alert("赋值变量的布尔值为:true")
                }
                else{
                    alert("未赋值变量的布尔值为:false")
            }
            var value1,value2=2;
            judge(value1);
            judge(value2);        
}    
        </script>