gpt4 book ai didi

JavaScript 比较失败

转载 作者:行者123 更新时间:2023-11-28 14:01:24 25 4
gpt4 key购买 nike

我正在尝试提示,然后比较两个值:

var x,y;
x = prompt("enter the first value","");
x = prompt("enter the second value","");

if( x > y)
{
alert("x>y");
}
else if(x < y)
{
alert("y>x")
}
else
{
alert("error");
}

每次运行此命令时,都会触发 alert("error") 行。我做错了什么?

最佳答案

您没有分配y:

x=prompt("enter the first value","");
x=prompt("enter the second value","");

两个赋值都分配了x

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

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