← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 57
  2. Hi, Kabir!
  3. .js
  4. 94
  5. 65
  6. console.log()
  7. 27
  8. 17
  9. 14
  10. <script>
  11. 19
  12. Welcome, Aman!
  13. actions and changes
  14. in the console
  15. a pop-up box
  16. alert()
  17. let
  18. 32
  19. 18
  20. 11
  21. 16
  22. 99
  23. 39
  24. 17
  25. if
  26. 91
  27. 57
  28. Hello, Meera!
  29. 16
  30. 17
  31. 81
  32. Well done, Meera!
  33. 32
  34. 26
  35. 15
  36. 34
  37. 55
  38. 70
  39. 45
  40. let

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