← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 27
  2. 20
  3. let
  4. in the console
  5. 15
  6. 0
  7. 78
  8. 14
  9. alert()
  10. a pop-up box
  11. .js
  12. Hi, Meera!
  13. console.log()
  14. 12
  15. Welcome, Aman!
  16. 45
  17. 63
  18. 18
  19. let
  20. 56
  21. 1
  22. if
  23. 10
  24. 64
  25. actions and changes
  26. 30
  27. 5
  28. 40
  29. 10
  30. 5
  31. 14
  32. 7
  33. 17
  34. Hi, Meera!
  35. 51
  36. 54
  37. Hi, Aman!
  38. 16
  39. 19
  40. <script>

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