Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript中的If循环失败_Javascript - Fatal编程技术网

Javascript中的If循环失败

Javascript中的If循环失败,javascript,Javascript,伙计们,我试图解决凯撒的密码,我写了一个完美的代码有一个问题使它无法工作,我将用一个更简单的代码演示它 var str ="abcz" let x = str.charCodeAt(3); console.log(x) //=122 if(18<x<121){console.log("Too young")} // it always goes to this function even if i get the code of a,b,

伙计们,我试图解决凯撒的密码,我写了一个完美的代码有一个问题使它无法工作,我将用一个更简单的代码演示它

var str ="abcz"
let x = str.charCodeAt(3); 
console.log(x) //=122
if(18<x<121){console.log("Too young")}   // it always goes to this function even if i get the code of a,b,c
else if(x>121) {console.log("zaza")} //it never reaches this point
var str=“abcz”
设x=str.charCodeAt(3);
控制台日志(x)/=122

如果(18就这样做

var str ="abcz"
let x = str.charCodeAt(3); 
console.log(x) //=122

if(18 < x && x < 121){console.log("Too young")}   

else if(x>121) {console.log("zaza")} 
var str=“abcz”
设x=str.charCodeAt(3);
控制台日志(x)/=122
if(18121){console.log(“zaza”)}

我认为JS解释器首先将
if(18<122)
计算为
true
,然后将
if(true<121)
计算为
true
。我的假设是
true
转换为
1
,与
121
进行数字比较。 如果(x>18&&x<121)
18
18,您的情况应该是这样的