Splitting Text
Break into words.
Splitting Text is a free Javascript for Kids lesson on CoddyKit — lesson 1 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.
Welcome to Word Counter! 📝
Hi, word wizard! 👋 We are going to build a Word Counter! 📝
It will count how many words are in a sentence. But first, we need to break a sentence into little word pieces! ✂️
What is a String? 🧵
In code, words and sentences are called strings. 🧵
A string is just text wrapped in quotes, like 'I love coding'. Let's print one! 💬
let sentence = 'I love coding';
console.log(sentence);Spaces Between Words 🫧
Look closely at a sentence. Between every word there is a space! 🫧
The space is like a little wall between words. We can use it to cut the sentence! ✂️
let sentence = 'cats and dogs';
console.log('This sentence has spaces between words!');
console.log(sentence);Meet split! ✂️
JavaScript has a magic tool called split! ✂️
It cuts a string into pieces wherever we tell it. We will cut at every space! 🫧
let sentence = 'cats and dogs';
let words = sentence.split(' ');
console.log(words);A List of Words 📋
Did you see the square brackets [ ]? 📋
That is an array! It is a list that holds each word separately. So neat! 🎉
let sentence = 'red blue green';
let words = sentence.split(' ');
console.log(words);
console.log('Nice, three separate words!');Pick One Word 👆
We can grab one word from the list using its position! 👆
Counting starts at 0 in code. So the first word is words[0]! 🥇
let words = 'apple banana cherry'.split(' ');
console.log('First word: ' + words[0]);
console.log('Second word: ' + words[1]);
console.log('Third word: ' + words[2]);Split a Longer Sentence 📜
Let's try a longer sentence! 📜
No matter how long it is, split cuts it into a tidy list of words. 🪄
let sentence = 'I want to be a coder';
let words = sentence.split(' ');
console.log(words);Split by Different Things 🔡
We do not have to split at spaces! We can split at any letter! 🔡
Here we cut a word at every letter 'a'. Try it! 😄
let word = 'banana';
let pieces = word.split('a');
console.log(pieces);Split Into Letters 🔠
If we split with empty quotes '', we cut between EVERY letter! 🔠
Now each letter is its own piece! Cool, right? 😎
let word = 'cat';
let letters = word.split('');
console.log(letters);A Splitting Helper 🛠️
Let's make a helper that splits a sentence and shows the pieces! 🛠️
We can reuse it for any sentence we like! 🔁
function splitWords(sentence) {
let words = sentence.split(' ');
console.log('Pieces: ');
console.log(words);
}
splitWords('the sky is blue');You Can Split Text! 🏆
Awesome job! 🏆 You learned how to split text!
- 🧵 Sentences are strings
- ✂️
split(' ')cuts at spaces - 📋 We get an array (a list) of words
Next, we will COUNT the words! 🔢
Quick Check ✅
Brain power! 🧠 What does split(' ') do to a sentence?
Lesson Recap 🎀
Great work, splitter! 🎀 Today you learned:
- 🧵 Text is a string
- ✂️
splitcuts text into pieces - 📋 We get an array (list) back
- 👆 We grab words with
[0],[1], ...
Next: counting all those words! 🔢
Frequently asked questions
Is the “Splitting Text” lesson free?
Yes — the full text of “Splitting Text” 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 “Splitting Text”?
Break into words. 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 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Splitting Text” 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
- Splitting Text
- Counting Words
- Counting Letters
- Longest Word