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