← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 62
  2. a pop-up box
  3. 21
  4. in the console
  5. <script>
  6. 53
  7. 48
  8. console.log()
  9. 66
  10. let
  11. Welcome, Riya!
  12. 35
  13. let
  14. 62
  15. 34
  16. 16
  17. for
  18. 3
  19. Welcome, Meera!
  20. 33
  21. 7
  22. 23
  23. 27
  24. 5
  25. Welcome, Arjun!
  26. 27
  27. 30
  28. 22
  29. Welcome, Aman!
  30. 7
  31. 36
  32. 4
  33. alert()
  34. 81
  35. 15
  36. 4
  37. Well done, Aman!
  38. actions and changes
  39. if
  40. 18

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