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