gpt4 book ai didi

javascript - 比较 userInput JavaScript

转载 作者:行者123 更新时间:2023-12-02 21:59:22 26 4
gpt4 key购买 nike

我在第二个输出上遇到错误。

var compareNumber = 3; // Code will be tested with: 3, 8, 42
var userNumber = '3'; // Code will be tested with: '3' 8, 'Hi'

/* Your Response goes Here*/

if (userNumber == compareNumber) {
console.log('Numbers are equal\nVariables are not identical');
} else {
console.log('Variables are not identical');
}

Error Image

最佳答案

请查看此内容以获取您的解决方案。

在 javascript == 中仅检查没有类型的值,因此 3 和 '3' 是相同的,因为值相同,尽管类型不同,所以这将返回 true

=== 匹配值和类型,因此 3 和 '3' 在这里不同,它将返回 false

var compareNumber = 8; // Code will be tested with: 3, 8, 42
var userNumber = 8; // Code will be tested with: '3' 8, 'Hi'

/* Your Response goes Here*/

if (userNumber === compareNumber) {
console.log('Numbers are identical');
} else if(userNumber == compareNumber){
console.log('Numbers are equal\nVariables are not identical');
} else {
console.log('Variables are not identical');
}

关于javascript - 比较 userInput JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59925936/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com