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