0Pricing
Javascript for Kids · Lesson

Decoding

Code to text.

Decoding is a free Javascript for Kids lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Javascript for Kids learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Crack the Code! 🔓

Decoding means turning a secret message back into normal words! Let's crack some codes! 🔓🕵️

console.log('Time to crack the code! 🔓')

The Opposite of Encoding 🔄

Encoding shifts letters FORWARD. Decoding shifts them BACK by the same amount! 🔄

console.log('Encode: forward ➡️')
console.log('Decode: backward ⬅️')

Slide One Letter Back ⬅️

If d was made by shifting a forward by 3, we slide it back by 3 to get a! ⬅️

let n = 'd'.charCodeAt(0)
console.log('d back by 3:', String.fromCharCode(n - 3))

We Need the Key 🗝️

To decode, we must know the secret shift key the sender used. Same key, both ways! 🗝️

let key = 3
console.log('The secret key is:', key)

Loop Through the Secret 🔁

We loop over the secret message and slide each letter back. 🔁

let secret = 'kh'
let key = 3
for (let i = 0; i < secret.length; i++) {
  console.log(String.fromCharCode(secret.charCodeAt(i) - key))
}

Collect the Real Message 📥

We glue the decoded letters into the real message! 📥

let secret = 'kh'
let key = 3
let real = ''
for (let i = 0; i < secret.length; i++) {
  real += String.fromCharCode(secret.charCodeAt(i) - key)
}
console.log('Real message:', real)

Decode a Full Word 🎉

Let's decode the secret khoor with key 3 and reveal it! 🎉

let secret = 'khoor'
let key = 3
let real = ''
for (let i = 0; i < secret.length; i++) {
  real += String.fromCharCode(secret.charCodeAt(i) - key)
}
console.log('Decoded:', real)

A Decode Function 🛠️

Let's make a reusable decode function! 🛠️

function decode(secret, key) {
  let out = ''
  for (let i = 0; i < secret.length; i++) {
    out += String.fromCharCode(secret.charCodeAt(i) - key)
  }
  return out
}
console.log(decode('ecv', 2))

Encode Then Decode 🔄

If we encode and then decode with the same key, we get our message back! 🔄

function shiftAll(msg, k) {
  let out = ''
  for (let i = 0; i < msg.length; i++) out += String.fromCharCode(msg.charCodeAt(i) + k)
  return out
}
let secret = shiftAll('hi', 3)
let back = shiftAll(secret, -3)
console.log('Secret:', secret, 'Back:', back)

Wrong Key, Wrong Message ❌

If you use the WRONG key, you get gibberish. That's what keeps it secret! ❌

function decode(s, k) {
  let out = ''
  for (let i = 0; i < s.length; i++) out += String.fromCharCode(s.charCodeAt(i) - k)
  return out
}
console.log('Right key:', decode('khoor', 3))
console.log('Wrong key:', decode('khoor', 1))

Full Decoder 🎮

Here is your complete code cracker! 🎮🔓

function decode(s, k) {
  let out = ''
  for (let i = 0; i < s.length; i++) out += String.fromCharCode(s.charCodeAt(i) - k)
  return out
}
console.log('Secret: phhw ph')
console.log('Real:', decode('phhw ph', 3))

Quick Check ✅

Final spy test! 🕵️

Master Spy! 🌟

Incredible work, agent! 🕵️ You finished Secret Code Maker! 🎉

  • Learned what codes are 🔐
  • Shifted letters ➡️
  • Encoded messages 📦
  • Decoded secrets 🔓

You are a true codebreaker! 🏆

console.log('Secret Code Maker: COMPLETE! 🌟🏆')

Frequently asked questions

Is the “Decoding” lesson free?

Yes — the full text of “Decoding” is free to read here on the web, and the Javascript for Kids course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Javascript for Kids course, upgrade to CoddyKit PRO.

What will I learn in “Decoding”?

Code to text. You practise Javascript for Kids with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Javascript for Kids?

No prior experience is required. Javascript for Kids on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Decoding” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Javascript for Kids lesson?

Yes. Every Javascript for Kids lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. What Is a Code?
  2. Shifting Letters
  3. Encoding
  4. Decoding
← Back to Javascript for Kids