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