Asking a Question
Get the players question.
Asking a Question is a free Javascript for Kids lesson on CoddyKit. This is 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, and your progress syncs across the web and the CoddyKit app. The Javascript for Kids course includes 4 lessons in total.
Welcome to Magic 8-Ball! 🎱
Hi there, fortune teller! 👋 We are building a Magic 8-Ball! 🎱
You ask it a question, give it a shake, and it tells you the future! 🔮 First, we need to get the player's question. Let's go!
What is a Question? ❓
A question is just text, like 'Will I get pizza tonight?' 🍕
In code, text is a string. Let's store a question in a box! 📦
let question = 'Will it be sunny tomorrow?';
console.log(question);Show the Question 💬
Let's make the 8-ball repeat the question back nicely! 💬
This makes it feel like it is really listening! 👂
let question = 'Will I be a great coder?';
console.log('🎱 You asked: ' + question);Try Your Own Question 🙋
Change the question to anything you want! 🙋
Ask about your day, your pet, or your dreams! 🌈
let question = 'Will my team win the game?';
console.log('🎱 The Magic 8-Ball hears: ' + question);An Asking Machine 🛠️
Let's make a machine that takes a question! 🛠️
The function ask gets a question and shows it nicely! 🤖
function ask(question) {
console.log('🎱 You asked: ' + question);
}
ask('Will it snow today?');Shake the Ball! 🌀
Before the answer comes, we shake the ball! 🌀
Let's add a fun shaking message to build excitement! 🥳
function ask(question) {
console.log('🎱 You asked: ' + question);
console.log('Shaking the ball... 🌀🌀🌀');
}
ask('Will I have fun today?');Check the Question 🔍
A good 8-ball makes sure you actually asked something! 🔍
We check if the question is empty using .length. 📏
let question = 'Is coding fun?';
if (question.length > 0) {
console.log('Great question! 🎱');
} else {
console.log('Please ask something! 🤔');
}Empty Question? 🤔
What if someone asks nothing? Let's test an empty question! 🤔
Our check catches it and asks them to try again! 😊
let question = '';
if (question.length > 0) {
console.log('Great question! 🎱');
} else {
console.log('You forgot to ask! Try again! 🤔');
}Make it Polite 🙏
Let's add a friendly greeting to our 8-ball! 🙏
It welcomes the player before taking their question! 😄
function ask(question) {
console.log('🔮 Welcome to the Magic 8-Ball!');
console.log('You asked: ' + question);
console.log('Hmm, let me think... 🤔');
}
ask('Will I learn to code?');Ask Many Questions 📋
Let's ask three questions in a row! 📋
Each one gets its own thinking moment! 🤔
function ask(question) {
console.log('🎱 ' + question);
}
ask('Will it rain?');
ask('Will I get a puppy?');
ask('Will today be awesome?');You Can Ask Questions! 🏆
Great job! 🏆 Your 8-ball can take questions!
- 📦 Store the question in a variable
- 💬 Show it back to the player
- 🔍 Check the question is not empty
Next: pick a random answer! 🎲
Quick Check ✅
Brain time! 🧠 How do we store the player's question so the 8-ball can use it?
Lesson Recap 🎀
Well done, fortune teller! 🎀 Today you learned:
- 📦 Store a question in a variable
- 💬 Show it back nicely
- 🔍 Check it is not empty with
.length - 🌀 Add a fun shaking message
Next: random answers! 🎲
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 “Asking a Question” lesson free?
Yes — the full text of “Asking a Question” 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 “Asking a Question”?
Get the players question. 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 1 of 4.
How long does the “Asking a Question” 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
- Asking a Question
- Random Answers
- Revealing the Fortune
- Add More Answers