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.⚡ What number does this code print?
let a = 6;
let b = 5;
console.log(a * b); -
2.⚡ What does this code show?
let name = "Kabir";
alert("Hi, " + name + "!"); (a) name (b) Hi, name! (c) Hi, Kabir! (d) Kabir -
3.⚡ What number does this code print?
let a = 15;
let b = 1;
console.log(a - b); - 4.⚡ Which JavaScript word writes in the console? (a) let (b) if (c) for (d) console.log()
-
5.⚡ What does this code show?
let name = "Meera";
alert("Welcome, " + name + "!"); (a) Welcome, name! (b) name (c) Welcome, Meera! (d) Meera -
6.⚡ What number does this code print?
let a = 9;
let b = 9;
console.log(a * b); -
7.⚡ What does this code print? (Look at the quotes!)
let x = "2";
let y = 8;
console.log(x + y); (a) 10 (b) Error (c) 28 -
8.⚡ What does this code show?
let name = "Meera";
console.log("Welcome, " + name + "!"); (a) Meera (b) Welcome, name! (c) name (d) Welcome, Meera! -
9.⚡ What number does this code print?
let a = 9;
let b = 9;
console.log(a - b); -
10.⚡ What number does this code print?
let a = 25;
let b = 14;
console.log(a + b); - 11.⚡ Which JavaScript word runs code when true? (a) alert() (b) let (c) if (d) console.log()
- 12.⚡ Which JavaScript word makes a new variable? (a) if (b) alert() (c) console.log() (d) let
-
13.⚡ What does this code show?
let name = "Riya";
alert("Hello, " + name + "!"); (a) Hello, Riya! (b) name (c) Riya (d) Hello, name! - 14.⚡ Which JavaScript word shows a pop-up box? (a) for (b) let (c) alert() (d) if
-
15.⚡ What number does this code print?
let a = 14;
let b = 11;
console.log(a - b); - 16.⚡ What does JavaScript add to a web page? (a) the page title (b) the domain name (c) only colours (d) actions and changes
-
17.⚡ What does this code print? (Look at the quotes!)
let x = "6";
let y = 2;
console.log(x + y); (a) 8 (b) 62 (c) Error -
18.⚡ What does this code print? (Look at the quotes!)
let x = "6";
let y = 4;
console.log(x + y); (a) 10 (b) 64 (c) Error - 19.⚡ What does alert() show? (a) a new tab (b) a table (c) a picture (d) a pop-up box
-
20.⚡ What number does this code print?
let a = 8;
let b = 26;
console.log(a + b); -
21.⚡ What number does this code print?
let a = 9;
let b = 8;
console.log(a * b); - 22.⚡ Which JavaScript word repeats code? (a) alert() (b) for (c) let (d) if
-
23.⚡ What does this code show?
let name = "Aman";
alert("Well done, " + name + "!"); (a) Aman (b) Well done, name! (c) Well done, Aman! (d) name -
24.⚡ What does this code show?
let name = "Kabir";
console.log("Hi, " + name + "!"); (a) Kabir (b) Hi, Kabir! (c) name (d) Hi, name! -
25.⚡ What number does this code print?
let books = 11;
books = books + 12;
books = books - 13;
console.log(books); -
26.⚡ What does this code show?
let name = "Riya";
alert("Welcome, " + name + "!"); (a) Welcome, name! (b) name (c) Welcome, Riya! (d) Riya -
27.⚡ What does this code show?
let name = "Arjun";
console.log("Hello, " + name + "!"); (a) Hello, name! (b) Arjun (c) name (d) Hello, Arjun! - 28.⚡ Which tag holds JavaScript in a page? (a) <code> (b) <js> (c) <style> (d) <script>
-
29.⚡ What does this code print? (Look at the quotes!)
let x = "2";
let y = 3;
console.log(x + y); (a) Error (b) 23 (c) 5 -
30.⚡ What number does this code print?
let marks = 28;
marks = marks + 13;
marks = marks - 20;
console.log(marks); -
31.⚡ What number does this code print?
let a = 21;
let b = 16;
console.log(a - b); -
32.⚡ What does this code show?
let name = "Aman";
console.log("Hi, " + name + "!"); (a) Aman (b) Hi, name! (c) name (d) Hi, Aman! -
33.⚡ What number does this code print?
let a = 13;
let b = 8;
console.log(a - b); -
34.⚡ What does this code show?
let name = "Riya";
console.log("Well done, " + name + "!"); (a) name (b) Well done, name! (c) Riya (d) Well done, Riya! - 35.⚡ Where does console.log() show its output? (a) in the console (b) in the address bar (c) on the printer (d) on the title bar
-
36.⚡ What does this code print? (Look at the quotes!)
let x = "1";
let y = 5;
console.log(x + y); (a) Error (b) 15 (c) 6 -
37.⚡ What number does this code print?
let marks = 25;
marks = marks + 17;
marks = marks - 27;
console.log(marks); -
38.⚡ What number does this code print?
let a = 35;
let b = 34;
console.log(a - b); -
39.⚡ What number does this code print?
let books = 23;
books = books + 6;
books = books - 26;
console.log(books); -
40.⚡ What does this code print? (Look at the quotes!)
let x = "2";
let y = 1;
console.log(x + y); (a) Error (b) 21 (c) 3
Answer key
- 30
- Hi, Kabir!
- 14
- console.log()
- Welcome, Meera!
- 81
- 28
- Welcome, Meera!
- 0
- 39
- if
- let
- Hello, Riya!
- alert()
- 3
- actions and changes
- 62
- 64
- a pop-up box
- 34
- 72
- for
- Well done, Aman!
- Hi, Kabir!
- 10
- Welcome, Riya!
- Hello, Arjun!
- <script>
- 23
- 21
- 5
- Hi, Aman!
- 5
- Well done, Riya!
- in the console
- 15
- 15
- 1
- 3
- 21
Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids