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