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