JavaScript Worksheet: Basics
Code tip (Line by line): let x = 5; makes a variable x holding 5; x = x + 2; changes it to 7. console.log(…) writes in the console; alert(…) shows a pop-up box. Text in quotes + anything = joined text: "5" + 3 → "53".
NameDateTime takenScore ___ / 40
- 1.⚡ Which JavaScript word makes a new variable? (a) alert() (b) console.log() (c) if (d) let
-
2.⚡ What does this code print? (Look at the quotes!)
let x = "9";
let y = 9;
console.log(x + y); (a) Error (b) 18 (c) 99 -
3.⚡ What number does this code print?
let a = 57;
let b = 13;
console.log(a - b); -
4.⚡ What does this code show?
let name = "Zoya";
console.log("Hello, " + name + "!"); (a) name (b) Zoya (c) Hello, name! (d) Hello, Zoya! -
5.⚡ What does this code print? (Look at the quotes!)
let x = "2";
let y = 2;
console.log(x + y); (a) 4 (b) Error (c) 22 - 6.⚡ Which JavaScript word writes in the console? (a) console.log() (b) if (c) for (d) let
- 7.⚡ Which tag holds JavaScript in a page? (a) <script> (b) <style> (c) <code> (d) <js>
-
8.⚡ What does this code show?
let name = "Arjun";
console.log("Hi, " + name + "!"); (a) Arjun (b) Hi, Arjun! (c) Hi, name! (d) name - 9.⚡ What does JavaScript add to a web page? (a) the page title (b) only colours (c) the domain name (d) actions and changes
- 10.⚡ Which word makes a new variable? (a) let (b) put (c) give (d) make
- 11.⚡ Where does console.log() show its output? (a) on the title bar (b) on the printer (c) in the address bar (d) in the console
- 12.⚡ Which JavaScript word repeats code? (a) if (b) for (c) alert() (d) let
-
13.⚡ What does this code show?
let name = "Riya";
alert("Welcome, " + name + "!"); (a) Welcome, Riya! (b) Riya (c) name (d) Welcome, name! -
14.⚡ What number does this code print?
let a = 35;
let b = 13;
console.log(a - b); -
15.⚡ What number does this code print?
let a = 16;
let b = 32;
console.log(a + b); - 16.⚡ Which JavaScript word shows a pop-up box? (a) for (b) alert() (c) let (d) console.log()
- 17.⚡ Which JavaScript word runs code when true? (a) alert() (b) for (c) let (d) if
-
18.⚡ What does this code show?
let name = "Kabir";
console.log("Well done, " + name + "!"); (a) Well done, Kabir! (b) name (c) Well done, name! (d) Kabir -
19.⚡ What does this code print? (Look at the quotes!)
let x = "8";
let y = 7;
console.log(x + y); (a) Error (b) 87 (c) 15 -
20.⚡ What does this code print? (Look at the quotes!)
let x = "8";
let y = 1;
console.log(x + y); (a) Error (b) 81 (c) 9 - 21.⚡ What does alert() show? (a) a picture (b) a pop-up box (c) a new tab (d) a table
-
22.⚡ What does this code show?
let name = "Kabir";
console.log("Hi, " + name + "!"); (a) name (b) Kabir (c) Hi, Kabir! (d) Hi, name! -
23.⚡ What number does this code print?
let score = 5;
score = score + 15;
score = score - 10;
console.log(score); -
24.⚡ What does this code print? (Look at the quotes!)
let x = "9";
let y = 2;
console.log(x + y); (a) 92 (b) Error (c) 11 -
25.⚡ What number does this code print?
let runs = 14;
runs = runs + 4;
runs = runs - 8;
console.log(runs); -
26.⚡ What does this code print? (Look at the quotes!)
let x = "1";
let y = 2;
console.log(x + y); (a) 3 (b) Error (c) 12 -
27.⚡ What does this code print? (Look at the quotes!)
let x = "1";
let y = 3;
console.log(x + y); (a) 4 (b) Error (c) 13 -
28.⚡ What number does this code print?
let books = 16;
books = books + 7;
books = books - 15;
console.log(books); -
29.⚡ What number does this code print?
let a = 12;
let b = 6;
console.log(a + b); -
30.⚡ What number does this code print?
let a = 2;
let b = 4;
console.log(a * b); -
31.⚡ What number does this code print?
let a = 11;
let b = 7;
console.log(a * b); -
32.⚡ What number does this code print?
let marks = 24;
marks = marks + 16;
marks = marks - 29;
console.log(marks); -
33.⚡ What number does this code print?
let a = 27;
let b = 11;
console.log(a - b); -
34.⚡ What number does this code print?
let runs = 19;
runs = runs + 17;
runs = runs - 18;
console.log(runs); -
35.⚡ What does this code print? (Look at the quotes!)
let x = "9";
let y = 6;
console.log(x + y); (a) Error (b) 96 (c) 15 -
36.⚡ What number does this code print?
let coins = 14;
coins = coins + 18;
coins = coins - 6;
console.log(coins); -
37.⚡ What does this code print? (Look at the quotes!)
let x = "6";
let y = 8;
console.log(x + y); (a) 68 (b) Error (c) 14 -
38.⚡ What does this code show?
let name = "Arjun";
alert("Well done, " + name + "!"); (a) Well done, name! (b) Well done, Arjun! (c) Arjun (d) name -
39.⚡ What does this code show?
let name = "Aman";
alert("Well done, " + name + "!"); (a) Well done, Aman! (b) name (c) Aman (d) Well done, name! -
40.⚡ What number does this code print?
let books = 20;
books = books + 7;
books = books - 4;
console.log(books);
Answer key
- let
- 99
- 44
- Hello, Zoya!
- 22
- console.log()
- <script>
- Hi, Arjun!
- actions and changes
- let
- in the console
- for
- Welcome, Riya!
- 22
- 48
- alert()
- if
- Well done, Kabir!
- 87
- 81
- a pop-up box
- Hi, Kabir!
- 10
- 92
- 10
- 12
- 13
- 8
- 18
- 8
- 77
- 11
- 16
- 18
- 96
- 26
- 68
- Well done, Arjun!
- Well done, Aman!
- 23
Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids