Chapter 1 deck Chapter 2 deck Chapter 3 deck Chapter 4 deck Chapter 5 deck Chapter 6 deck Chapter 7 deck Chapter 8 deck Chapter 9 deck Chapter 10 deck Chapter 11 deck Chapter 12 deck Chapter 13 deck Chapter 14 deck

Writing Output to the Page

3 slides · use ←/→ or Space to navigate, F for fullscreen.

Reading view

← Back to the full Chapter 5 deck

Writing Output to the Page
Fullscreen for presentation · Print / PDF for a handout
1 / 3
Lesson

Writing Output to the Page

The five ways to display JavaScript output.

Writing Output to the Page

Five Ways to Display Output

MethodPurpose
window.alert("text")Shows a pop-up alert dialog to the user.
document.write(value)Writes content into the HTML document. No newline added.
document.writeln(value)Like document.write() but adds a newline after each call.
element.innerHTMLSets the HTML content of a specific element by its ID.
console.log("text")Writes to the browser's developer console. Great for debugging.
window.alert("Hello!");                       // pop-up dialog
document.write("Hello from JS");              // writes into the page
document.writeln("Next line");                // write + newline
document.getElementById("demo").innerHTML = "Hello!";  // set element content
console.log("Debugging value");               // developer console

console.log() is your best friend for debugging — open DevTools (F12) and check the Console tab.

Writing Output to the Page

Activity — complete the code

Complete the five ways of writing output.

// 1. Pop-up dialog
window.("text");
 
// 2. Write into the document
document.("value");
 
// 3. Set an element content by id
document.getElementById("demo"). = "value";
 
// 4. Write to the developer console
console.("text");