Quick actions

cmd+k|ctrl+k

Navigation

Languages

Backend03

Snippet info

Language

JavaScript

Visibility

public

Author

64160280

Created

2023-09-28T08:07:58.060974Z

Updated

2023-09-28T08:19:42.099153Z

function exam03(shift, plaintext) {

    // declare variables
    let text = [];
    let charCode_ascii = [];
    let charCode = '';

    //loop for transform char to ascii number and + shift -> new char text
    for(let lengthText = 0; lengthText < plaintext.length; lengthText++) {
        text[lengthText] = plaintext[lengthText];
        charCode_ascii[lengthText] = text[lengthText].charCodeAt();
        charCode += String.fromCharCode(((charCode_ascii[lengthText] + shift) <= 90) ? charCode_ascii[lengthText] + shift
            : (charCode_ascii[lengthText] + shift) % 90 + 64);
    }
    return charCode;
}




function test_01() {
    if (exam03(3, "ABC") === "DEF") {
        console.log("pass");
    } else {
        console.log("fail");
    }
    if (exam03(3, "ZXY") === "CAB") {
        console.log("pass");
    } else {
        console.log("fail");
    }
}

test_01();
INFO