← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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