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