function myFunction2() {
var booloo = document.getElementById('texa').value;
if (!document.getElementById('texa').value) {
//var res = booloo.lastcharAt(booloo.value);
console.log("nothing");
} else if (booloo.substring(booloo.length - 1) == "+" || "-" || "*" || "/") {
console.log("String Contain Operator at last");
} else if (booloo.substring(booloo.length - 1) == "0" || "1" || "2" || "3" || "4" || "5" || "6" || "7" || "8" || "9") {
console.log("String contain Operand at last");
}
}
<html>
<body>
<input types="text" id="texa">
<button onclick="myFunction2()">Try it</button>
</body>
</html>
I'm trying to use multiple if else blocks in my code but at third block("String contain Operand at last") this is not working only remaining two blocks are working perfect. my objectives are if user type value like e.g 10+ value then it goes in second block that operator contain at last. and if suppose user type 10+2 then it must goes into third block like ("contain Operand at last") but the problem is it does not goes into third block.
Aucun commentaire:
Enregistrer un commentaire