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