← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 15
  2. alert()
  3. 25
  4. 36
  5. Hello, Riya!
  6. <script>
  7. Hi, Kabir!
  8. Welcome, Kabir!
  9. 20
  10. 27
  11. if
  12. let
  13. Welcome, Meera!
  14. 47
  15. a pop-up box
  16. actions and changes
  17. 29
  18. .js
  19. 92
  20. 25
  21. 5
  22. 52
  23. 76
  24. 26
  25. 71
  26. 4
  27. 32
  28. console.log()
  29. 29
  30. 10
  31. 0
  32. let
  33. 60
  34. 9
  35. 55
  36. 4
  37. 74
  38. 14
  39. Hello, Meera!
  40. in the console

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