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