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();