← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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