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