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