← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. Hello, Aman!
  2. 86
  3. 57
  4. 36
  5. 36
  6. if
  7. in the console
  8. Hi, Arjun!
  9. let
  10. for
  11. 83
  12. Well done, Aman!
  13. .js
  14. 91
  15. console.log()
  16. 17
  17. 46
  18. 46
  19. 60
  20. 42
  21. 80
  22. <script>
  23. alert()
  24. 35
  25. Welcome, Aman!
  26. Hello, Zoya!
  27. let
  28. 84
  29. 12
  30. actions and changes
  31. 39
  32. 14
  33. Welcome, Arjun!
  34. 31
  35. 38
  36. 32
  37. 32
  38. 30
  39. 62
  40. a pop-up box

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