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