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