Change the colour and read what is typed
Section 3: JavaScript: the actionsLesson 3.5 · ⏱ 8 min
HTML
<div id="box"></div>
<button id="go">Change colour</button>
CSS
body { font-family: Tahoma; text-align: center; }
#box { width: 160px; height: 160px; margin: 20px auto; background: orange; border-radius: 20px; }
JavaScript
const box = document.getElementById("box");
document.getElementById("go").onclick = function () {
box.style.background = "#5B3DF5";
};
🖥️ The page in Robo Web:

HTML
<input id="name" placeholder="Your name">
<button id="go">go</button>
<h2 id="out"></h2>
CSS
body { font-family: Tahoma; text-align: center; padding: 20px; }
input, button { font-size: 20px; padding: 6px 12px; }
JavaScript
document.getElementById("go").onclick = function () {
const name = document.getElementById("name").value;
document.getElementById("out").textContent = "Hello, " + name + "!";
};
🖥️ The page in Robo Web:

📌 Another example: colours from a text box
We type the name of a colour in English, and the background turns that colour.
HTML
<input id="c" placeholder="red, gold, pink...">
<button id="go">Colour it</button>
CSS
body { font-family: Tahoma, sans-serif; }
button { font-size: 20px; padding: 8px 20px; }
input { font-size: 20px; }
JavaScript
document.getElementById("go").onclick = function () {
const color = document.getElementById("c").value;
document.body.style.background = color;
};
🖥️ The page in Robo Web:

✍️ Practise
A button that changes the colour.
✍️ Practise here in the lesson✖ Close the labor open the lab in a new page ↗
✍️ Practise
Read what the visitor types.
✍️ Practise here in the lesson✖ Close the labor open the lab in a new page ↗
🎯 Challenge yourself
Easy
A button that makes the background pink.
👀 Show the solution🙈 Hide the solution
HTML
<button id="go">Pink</button>
CSS
body { font-family: Tahoma, sans-serif; }
button { font-size: 20px; padding: 8px 20px; }
JavaScript
document.getElementById("go").onclick = function () {
document.body.style.background = "pink";
};
🖥️ The page in Robo Web:

Result: a pink background.
Medium
A button that makes the words 4 pixels bigger with every click.
👀 Show the solution🙈 Hide the solution
HTML
<p id="t">Make me bigger</p>
<button id="big">A+</button>
CSS
body { font-family: Tahoma, sans-serif; }
button { font-size: 20px; padding: 8px 20px; }
#t { font-size: 16px; }
JavaScript
let size = 16;
document.getElementById("big").onclick = function () {
size = size + 4;
document.getElementById("t").style.fontSize = size + "px";
};
🖥️ The page in Robo Web:

Result: 3 clicks: 28px.
Hard
A text box for the name and another for the age, and the button writes a sentence with both.
👀 Show the solution🙈 Hide the solution
HTML
<input id="name" placeholder="Your name">
<input id="age" type="number" placeholder="Your age">
<button id="go">Introduce me</button>
<p id="res"></p>
CSS
body { font-family: Tahoma, sans-serif; }
button { font-size: 20px; padding: 8px 20px; }
JavaScript
document.getElementById("go").onclick = function () {
const name = document.getElementById("name").value;
const age = Number(document.getElementById("age").value);
document.getElementById("res").textContent = name + " is " + age + ", and in a year he will be " + (age + 1);
};
🖥️ The page in Robo Web:

Result: Youssef is 11, and in a year he will be 12

