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)
1818,您的情况应该是这样的