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