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