Skip to content

Latest commit

 

History

History
139 lines (106 loc) · 3.11 KB

File metadata and controls

139 lines (106 loc) · 3.11 KB

Solution Code - Console Secret Message Decoder

Step 1 Solution - Create a Structured Prompt for User Input JavaScript – script.js
let codedMessage = "";

// ===== Step 1 =====
console.log("Decoder scaffold loaded. Follow the steps in the instructions.");

codedMessage = prompt("Type a coded phrase in leet speak (e.g., 7h3 quick br0wn f0x)");
console.log("Raw input:", codedMessage);
Step 2 Solution – Set Up Your Loop JavaScript – `script.js`
let decodedMessage = "";

for (let i = 0; i < codedMessage.length; i++) {
  let currentChar = codedMessage.charAt(i);
  console.log(i, currentChar); 
  // Step 3 will add logic for decoding each character.
}
Step 3A Solution – Start Applying Transformation Rules JavaScript – `script.js`
let decodedMessage = "";

for (let i = 0; i < codedMessage.length; i++) {
  let currentChar = codedMessage.charAt(i);

  if (currentChar === "0") {
    currentChar = "O";
  } else {
    currentChar = currentChar.toUpperCase();
  }

  decodedMessage = decodedMessage + currentChar;
}

console.log("Decoded message:", decodedMessage);
Step 3B Solution – Add More Transformation Rules JavaScript – `script.js`
let decodedMessage = "";

for (let i = 0; i < codedMessage.length; i++) {
  let currentChar = codedMessage.charAt(i);

  if (currentChar === "0") {
    currentChar = "O";
  } else if (currentChar === "1") {
    currentChar = "L";
  } else if (currentChar === "3") {
    currentChar = "E";
  } else if (currentChar === "4") {
    currentChar = "A";
  } else if (currentChar === "7") {
    currentChar = "T";
  } else {
    currentChar = currentChar.toUpperCase();
  }

  decodedMessage = decodedMessage + currentChar;

}   
Step 4 Solution – Display the Decoded Message
// Testing step - follow code review steps. No new code additions required. 
Final Solution

JavaScript - script.js

// ===== Console Secret Message Decoder =====
// Try: h3110, 7h3 quick br0wn f0x, 1337

console.log("Decoder scaffold loaded. Follow the steps in the instructions.");

// Step 1: Capture input
let codedMessage = prompt("Type a coded phrase in leet speak (e.g., 7h3 quick br0wn f0x)");
console.log("Raw input:", codedMessage);

// Step 2: Prepare accumulator and loop
let decodedMessage = "";

for (let i = 0; i < codedMessage.length; i++) {
  let currentChar = codedMessage.charAt(i);

  // Steps 3–4: Apply rules
  if (currentChar === "0") {
    currentChar = "O";
  } else if (currentChar === "1") {
    currentChar = "L";
  } else if (currentChar === "3") {
    currentChar = "E";
  } else if (currentChar === "4") {
    currentChar = "A";
  } else if (currentChar === "7") {
    currentChar = "T";
  } else {
    currentChar = currentChar.toUpperCase();
  }

  // Append to result
  decodedMessage = decodedMessage + currentChar;
}

// Step 5: Show result
console.log("Decoded message:", decodedMessage);