← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 71
  2. 12
  3. 54
  4. in the console
  5. .js
  6. a pop-up box
  7. 39
  8. 57
  9. 77
  10. 75
  11. let
  12. 45
  13. alert()
  14. for
  15. 58
  16. Well done, Kabir!
  17. 69
  18. let
  19. 16
  20. 1
  21. 23
  22. 54
  23. 42
  24. 85
  25. 19
  26. 94
  27. 32
  28. 48
  29. 30
  30. console.log()
  31. 5
  32. 27
  33. 45
  34. Well done, Arjun!
  35. 1
  36. if
  37. 6
  38. <script>
  39. 22
  40. actions and changes

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