Javascript for Kids · Lesson

Shifting Letters

A simple cipher.

Lesson 2 of 413 steps

Shifting Letters is a free Javascript for Kids lesson on CoddyKit. This is lesson 2 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, and your progress syncs across the web and the CoddyKit app. The Javascript for Kids course includes 4 lessons in total.

The Sliding Trick! ➡️

Today we learn the Caesar Cipher: we slide every letter forward a few steps! ➡️🔐

console.log('Let us slide some letters! ➡️')

Slide by One 1️⃣

If we shift a forward by 1, it becomes b. Easy! 1️⃣

let n = 'a'.charCodeAt(0)
console.log('a shifted by 1:', String.fromCharCode(n + 1))

Slide by Three 3️⃣

The famous Caesar shift is 3. So a becomes d! 3️⃣

let n = 'a'.charCodeAt(0)
console.log('a shifted by 3:', String.fromCharCode(n + 3))

Shift Any Letter 🔤

Let's make a shift amount variable so we can change it easily! 🔤

let shift = 3
let letter = 'h'
let n = letter.charCodeAt(0)
console.log(letter, 'becomes', String.fromCharCode(n + shift))

Shift a Whole Word 🔁

With a loop we can shift every letter in a word! 🔁

let word = 'cat'
let shift = 1
for (let i = 0; i < word.length; i++) {
  let n = word.charCodeAt(i)
  console.log(String.fromCharCode(n + shift))
}

Build the Secret Word 🧩

Instead of printing each letter, let's glue them into one secret word! 🧩

let word = 'cat'
let shift = 1
let secret = ''
for (let i = 0; i < word.length; i++) {
  secret = secret + String.fromCharCode(word.charCodeAt(i) + shift)
}
console.log('Secret:', secret)

Sliding Back ⬅️

To read a secret, we slide the letters BACK by the same amount! ⬅️

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

What About Z? 🌀

If we shift z forward, it goes past the alphabet! Real ciphers wrap around back to a. 🌀

console.log('z is tricky! It should wrap to a 🌀')

A Shift Function 🛠️

Let's wrap our slider in a reusable function! 🛠️

function shiftLetter(letter, amount) {
  return String.fromCharCode(letter.charCodeAt(0) + amount)
}
console.log(shiftLetter('a', 2))

Try Different Shifts 🔢

A bigger shift makes a different secret. Try shifting by 5! 🔢

function shiftLetter(l, a) { return String.fromCharCode(l.charCodeAt(0) + a) }
console.log('Shift 5:', shiftLetter('a', 5))
console.log('Shift 10:', shiftLetter('a', 10))

Full Shift Demo 🎮

Here is a full word getting shifted into a secret! 🎮

let word = 'dog'
let shift = 2
let secret = ''
for (let i = 0; i < word.length; i++) {
  secret += String.fromCharCode(word.charCodeAt(i) + shift)
}
console.log(word, 'becomes', secret)

Quick Check ✅

Test your sliding skills! 🧠

Letter Slider! 🌟

Awesome, agent! 🕵️ You learned to shift letters! 🎉

  • Slide forward to hide ➡️
  • Slide back to read ⬅️
  • Loops shift whole words 🔁

Next: encoding a full message! 🔐

console.log('Shifting letters: LEARNED! 🌟')
Free to start

Learn JavaScript with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
35
Lessons
140

Frequently Asked Questions

Is the “Shifting Letters” lesson free?

Yes — the full text of “Shifting Letters” is free to read here on the web. 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. The Javascript for Kids course includes 4 lessons in total.

What will I learn in “Shifting Letters”?

A simple cipher. 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, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 4.

How long does the “Shifting Letters” 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