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