Как мне не допустить, чтобы значение acii столиц превышало - PullRequest
0 голосов
/ 06 октября 2019

Мое утверждение if, кажется, не работает, и я не понимаю, почему. Мне нужно, чтобы значение ascii "newcode" не превышало значение ascii для заглавных букв.

 document.getElementById("message").innerHTML  = ("<h2>&nbsp;</h2>");
 var msg= prompt("Enter your message." , " ");
 var newmsg = " ";
 var upCaseCode = 155;
 var newCode = 0;
 var usercode = 0;
 var lowCaseCode = 219;
 var specialCode = 3;
 var random_num = (Math.floor(Math.random() * 10)) + 1;
 console.log(random_num);

 //the loop encodes each letter in the message string
 for (var j = 0; j < msg.length; j++)
 {
     //check for upppercase letters and encode them
     if ((msg.charCodeAt(j) >= 65) && (msg.charCodeAt(j) <= 90))
        {   usercode = (random_num + msg.charCodeAt(j));    
                if (usercode >= 91)
                    {
                        newcode = usercode - 26;
                    }
                else (usercode <= 64)
                    {
                        newcode = usercode + 26;
                    }

                usercode = newCode;

                console.log(newCode)
        }
    else 
    //check for lowercase letters and encode them
         if ((msg.charCodeAt(j) >= 97) && (msg.charCodeAt(j) <= 122)) 
            {   newcode = ((lowCaseCode + random_num) - msg.charCodeAt(j)); }
        else
    //check for numbers and special characters and encode them
            if (((msg.charCodeAt(j) > 90) && (msg.charCodeAt(j) < 97)) || (msg.charCodeAt(j) < 65))
               {    newcode = (msg.charCodeAt(j) + specialCode);    }
    //add each encoded character to the new message
      newmsg = newmsg + " " + String.fromCharCode(newcode);
 }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...