一直没有结果
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”
用函数完成下图效果
函数结尾少了括号了{}
少了个花括号
<!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>