Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

370
Views
JavaScript code doesn't work, no errors or stops

I am new to JavaScript and I try to write a decoder to caesar cipher. But my code doesn't work, and there is no errors shown and it doesn't stop.

let word = "привет";
let shift = 3;
let result = "";
for (let i = 0; i < word.legth; i++){
    if ('А'.charCodeAt(0) <= word[i].charCodeAt(0) <= 'Я'.charCodeAt(0)) {
        let char = ((word[i].charCodeAt(0) + shift - 'А'.charCodeAt(0)) % 32) + 'А'.charCodeAt(0)
        result = result + String.fromCharCode(char);
    }
    else if ('а'.charCodeAt(0) <= word[i].charCodeAt(0) <= 'я'.charCodeAt(0)) {
        let char = ((word[i].charCodeAt(0) + shift - 'а'.charCodeAt(0)) % 32) + 'а'.charCodeAt(0)
        result = result + String.fromCharCode(char);
    }
    else {
        result = result + word[i];
    }
}
console.log(result)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Change word.legth to word.length

let word = 'привет';
let shift = 3;
let result = '';
for (let i = 0; i < word.length; i++) {
    if ('А'.charCodeAt(0) <= word[i].charCodeAt(0) <= 'Я'.charCodeAt(0)) {
        let char =
            ((word[i].charCodeAt(0) + shift - 'А'.charCodeAt(0)) % 32) +
            'А'.charCodeAt(0);
        result = result + String.fromCharCode(char);
    } else if (
        'а'.charCodeAt(0) <=
        word[i].charCodeAt(0) <=
        'я'.charCodeAt(0)
    ) {
        let char =
            ((word[i].charCodeAt(0) + shift - 'а'.charCodeAt(0)) % 32) +
            'а'.charCodeAt(0);
        result = result + String.fromCharCode(char);
    } else {
        result = result + word[i];
    }
}
console.log(result);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!