← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

HTML and CSS lesson 25: JavaScript basics · Set 188 · 40 questions
TalentJR

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. 1.⚡ What number does this code print?
    let coins = 27;
    coins = coins + 2;
    coins = coins - 22;
    console.log(coins);
  2. 2.⚡ Which JavaScript word writes in the console? (a) let (b) if (c) console.log() (d) alert()
  3. 3.⚡ What number does this code print?
    let coins = 10;
    coins = coins + 5;
    coins = coins - 5;
    console.log(coins);
  4. 4.⚡ What does this code show?
    let name = "Zoya";
    console.log("Hello, " + name + "!");
    (a) Zoya (b) Hello, Zoya! (c) name (d) Hello, name!
  5. 5.⚡ Which JavaScript word repeats code? (a) for (b) console.log() (c) alert() (d) if
  6. 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. 7.⚡ What number does this code print?
    let apples = 30;
    apples = apples + 2;
    apples = apples - 1;
    console.log(apples);
  8. 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. 9.⚡ A JavaScript file usually ends with which extension? (a) .css (b) .jpg (c) .html (d) .js
  10. 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. 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. 12.⚡ What number does this code print?
    let runs = 30;
    runs = runs + 6;
    runs = runs - 17;
    console.log(runs);
  13. 13.⚡ What number does this code print?
    let a = 41;
    let b = 1;
    console.log(a - b);
  14. 14.⚡ What number does this code print?
    let a = 37;
    let b = 3;
    console.log(a + b);
  15. 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. 16.⚡ What number does this code print?
    let a = 24;
    let b = 20;
    console.log(a - b);
  17. 17.⚡ What number does this code print?
    let a = 29;
    let b = 13;
    console.log(a - b);
  18. 18.⚡ What number does this code print?
    let a = 35;
    let b = 1;
    console.log(a + b);
  19. 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. 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. 21.⚡ Which word makes a new variable? (a) make (b) give (c) put (d) let
  22. 22.⚡ What number does this code print?
    let a = 6;
    let b = 2;
    console.log(a * b);
  23. 23.⚡ Which tag holds JavaScript in a page? (a) <code> (b) <js> (c) <style> (d) <script>
  24. 24.⚡ What number does this code print?
    let a = 12;
    let b = 40;
    console.log(a + b);
  25. 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. 26.⚡ Which JavaScript word makes a new variable? (a) console.log() (b) for (c) let (d) if
  27. 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. 28.⚡ What does this code show?
    let name = "Zoya";
    console.log("Welcome, " + name + "!");
    (a) Welcome, Zoya! (b) Welcome, name! (c) name (d) Zoya
  29. 29.⚡ What number does this code print?
    let score = 25;
    score = score + 7;
    score = score - 8;
    console.log(score);
  30. 30.⚡ Which JavaScript word runs code when true? (a) for (b) alert() (c) if (d) let
  31. 31.⚡ What number does this code print?
    let books = 9;
    books = books + 8;
    books = books - 15;
    console.log(books);
  32. 32.⚡ What does this code show?
    let name = "Riya";
    alert("Hello, " + name + "!");
    (a) Hello, name! (b) Hello, Riya! (c) name (d) Riya
  33. 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. 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. 35.⚡ Which JavaScript word shows a pop-up box? (a) alert() (b) for (c) let (d) if
  36. 36.⚡ What does this code show?
    let name = "Meera";
    console.log("Welcome, " + name + "!");
    (a) Welcome, Meera! (b) Welcome, name! (c) name (d) Meera
  37. 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. 38.⚡ What does this code show?
    let name = "Riya";
    console.log("Welcome, " + name + "!");
    (a) Welcome, name! (b) Riya (c) Welcome, Riya! (d) name
  39. 39.⚡ What number does this code print?
    let books = 8;
    books = books + 11;
    books = books - 19;
    console.log(books);
  40. 40.⚡ What number does this code print?
    let marks = 9;
    marks = marks + 3;
    marks = marks - 1;
    console.log(marks);

Answer key

  1. 7
  2. console.log()
  3. 10
  4. Hello, Zoya!
  5. for
  6. in the console
  7. 31
  8. actions and changes
  9. .js
  10. Well done, Aman!
  11. 59
  12. 19
  13. 40
  14. 40
  15. 96
  16. 4
  17. 16
  18. 36
  19. 47
  20. 99
  21. let
  22. 12
  23. <script>
  24. 52
  25. 31
  26. let
  27. 32
  28. Welcome, Zoya!
  29. 24
  30. if
  31. 2
  32. Hello, Riya!
  33. 72
  34. 97
  35. alert()
  36. Welcome, Meera!
  37. 25
  38. Welcome, Riya!
  39. 0
  40. 11

Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids