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