JavaScript, the Console and Dialog Boxes
- 6 min reading
- 6 min activity
0 of 5 tasks doneup to 95 XP
Mission 4: Bring it to life. Your website has structure and style. Now JavaScript makes it react.
- Say what JavaScript does and where
<script>goes. - Write to the console with
log,warn,errorandtable. - Use
alert(),prompt()andconfirm(); read the window size and the address.
In lesson 1.3 you met the tags in the head. One of them brings JavaScript into a page.
Quick recall
What JavaScript does
JavaScript is the programming language of web pages. It makes a page react: it opens a menu, checks a form, changes text. It runs in the visitor's browser, so it is fast. It looks a little like C and Java, but it is a separate language.
Where the code goes
Put <script> right before </body>: the browser shows the page first, and your code finds every element. The code can be in its own file:
<script src="script.js"></script>
</body>
In the head, add defer: the script waits until the HTML is ready. Here, the practice space puts your JavaScript at the end of the page.
The console
On a computer, F12 or Ctrl+Shift+I (on a Mac Cmd+Option+I) opens the developer tools: Elements (HTML and CSS), Console (messages and errors) and Sources (your files). Phones have no developer tools, so every exercise here has a Console box.
| Code | What you see |
|---|---|
console.log("Age:", age); | A normal message; a comma adds values. |
console.warn("Check this"); | A yellow warning. The code keeps running. |
console.error("Saving failed"); | A red error message. |
console.table(["Ayla", "Lena"]); | A table with an index and a value column. |
console.clear(); | An empty console. |
The slide on console.error() has a lone } under the line. Nothing opened it, so the code stops. Leave it out.
What does each method do?
Now write all four kinds of messages. This exercise counts for the Console Detective badge.
Console messages
Mission 4 starts here. Add a warning, an error and a table, then read every message in the Console box.
The window and dialog boxes
window is the browser window. Everything lives inside it, so alert("Hi") is the same as window.alert("Hi").
window.innerWidthandinnerHeight: the size of the browser window in pixels.location.href: the page address. A new address opens another page;location.reload()loads the page again.alert("Saved!"): a message with an OK button.prompt("Your name?"): asks for text. You get the text, ornull("empty on purpose") after Cancel.confirm("Delete this?"):truefor OK,falsefor Cancel.
let sure = confirm("Do you really want to delete this entry?");
if (sure) {
console.log("The entry was deleted.");
} else {
console.log("Nothing was deleted.");
}
These boxes stop the whole page, so websites use them rarely. Here they appear in the Console: prompt() and confirm() use the answers under "Answers", and a new address shows as "Go to: ...".
Which box asks for text?
Worked example: a simple redirect panel
Sofia builds an entry panel for the website of her running club.
- Ask
confirm(): does the visitor want to enter? The answer goes intoallowed. - Ask again
If yes,
prompt()asks for a name. - Check and greet
if (name && name.length > 0): a name with at least one letter? Thenalert()greets, andconsole.table()shows the window size and language. - React to no
console.error()notes it, andlocation.hrefsends the visitor to another page.
The greeting is a template literal: backticks with ${name} inside (lesson 4.4). The slide sends visitors to a search engine; we use https://example.com, an address made for examples.
Simple redirect panel
The daily application from the course slides. Put the blocks in the right order. The practice space answers the boxes for you: OK, then the name Ayla.
- JavaScript
- The programming language that makes web pages react.
- Console
- A panel for developers with messages and errors.
- Developer tools
- Browser tools for HTML, CSS, files and the console.
- Dialog box
- A small box from
alert(),prompt()orconfirm(). - null
- A value that means "empty on purpose".
In short
- JavaScript makes a page react.
<script>goes before</body>, or in the head withdefer. console.log(),warn(),error()andtable()show what your code does.alert()tells,prompt()asks for text,confirm()asks OK or Cancel.
Your JavaScript finds elements on the page and changes their text, colour and HTML.
Sources
- MDN Web Docs (2026). What is JavaScript?
- MDN Web Docs (2026). <script>: The Script element.
- MDN Web Docs (2026). What are browser developer tools?
- MDN Web Docs (2026). console and console.table().
- MDN Web Docs (2026). Window: prompt() method and Window: confirm() method.
- MDN Web Docs (2026). Window: innerWidth property and Location: href property.
End of the lesson
This lesson: 0 of 105 XP
Code Cards in this lesson: 8
JavaScriptconsole.log()console.warn()console.table()windowalert()prompt()null