
Course 2 – Programming with JavaScript quiz answers
Week 1: Introduction to JavaScript
Meta Front-End Developer Professional Certificate
Complete Coursera Answers & Study Guide
Click to Enroll in Coursera Meta Front-End Professional Certificate
TABLE OF CONTENT
- INTRODUCTION
- SELF REVIEW: DECLARING VARIABLES
- SELF REVIEW – ADVANCED USE OF OPERATORS
- KNOWLEDGE CHECK: WELCOME TO PROGRAMMING
- SELF REVIEW: PRACTICE CONDITIONAL STATEMENTS
- SELF REVIEW: REPETITIVE TASKS WITH LOOPS
- SELF REVIEW: WORKING WITH CONDITIONALS AND LOOPS
- KNOWLEDGE CHECK – CONDITIONALS AND LOOPS
- MODULE QUIZ: INTRODUCTION TO JAVASCRIPT
- CONCLUSION
Introduction to JavaScript INTRODUCTION
This module is part of Coursera’s Meta Front-End Developer Professional Certificate and provides an introduction to JavaScript. Through this course, you will learn the basics of JavaScript, such as why it is important in software development, how to write code inside a browser, the common operators used, conditional statements, and loops. Once completing this course, you will have achieved the following learning objectives: Understand basic JavaScript syntax; Know when and how to use different data types; Write lines of code using variables, conditionals, and loops; Use arrays, objects, and functions effectively; Explain client-side scripting with HTML5.
With these skills under your belt, you’ll be well on your way to becoming a successful web developer! Good luck!
Learning Objectives
- Explain the importance of JavaScript in software development
- Demonstrate how to write JavaScript code inside the browser
- Demonstrate how to write basic JavaScript code: List common operators, conditional statements and loops
- Demonstrate how to use variables and output their values in the console
SELF REVIEW: DECLARING VARIABLES
1. Did you complete the Declaring variables exercise?
- Yes (Correct)
- No
Correct: Well done on completing the exercise! While this was repetitive, it does help to engrain the activity of declaring variables and checking their values. It’s something that you will do every day as a developer.
2. Are you comfortable with using console.log?
- Yes (Correct)
- No
3. Are you comfortable using the assignment operator?
- Yes (Correct)
- No
Correct: Great! Understanding that the = operator is the assignment operator in JavaScript, is a very important concept to have a handle on.
4. In JavaScript you can declare a variable with the keyword var. Which one of the following statements about var is correct?
- Var allows you to save a variable so that you can re-use it in future. (Correct)
- Var allows you to assign a value to a variable.
- You use var to change the value of a variable.
Correct: Yes, that’s correct! Var makes your life as a programmer easier by allowing you to re-use a variable multiple times.
SELF REVIEW – ADVANCED USE OF OPERATORS
1. Did you complete the Advanced use of operators exercise?
- Yes (Correct)
- No
Correct: Well done on completing the exercise!
2. Did you find any part of the exercise on the Advanced Use of Operators difficult?
- Yes (Correct)
- No
Correct: Thank you for completing the Advanced Use of Operators exercise.
3. Would you say that you are able to explain, in your own words, how logical operators &&, ||, and ! work in JavaScript?
- Yes (Correct)
- No
Correct: Great! Being able to describe newly-learned concepts in your own words is a reflection of a better understanding of the subject matter.
KNOWLEDGE CHECK: WELCOME TO PROGRAMMING
1. What is the data type of the value “Hello, World”?
- String (Correct)
- number
- boolean
Correct: That’s correct! The value of “Hello, World” is of the string data type.
2. What is the data type of the value true ?
- string
- number
- Boolean (Correct)
Correct: That’s correct! The values of true and `false are of the boolean data type.
3. What is the % operator?
- The modulus operator (Correct)
- The division operator
- The concatenation operator
Correct: That’s correct! The modulus operator is represented using the % symbol.
4. What happens when you use the + operator on two strings?
- They get joined into a single string (Correct)
- You can’t use the + operator on two strings
Correct: That’s correct! Using the + operator on two strings joins the strings together.
5. What is the operator symbol && represent in JavaScript?
- The logical OR operator
- The logical AND operator (Correct)
- The logical NOT operator
Correct: That’s correct! In JavaScript, the && is the logical AND operator.
6. What happens when you use the + operator on a string and a number?
- Nothing – you can’t use the + operator on different data types
- They get joined together as if both of them were strings (Correct)
Correct: Using the + operator on a string and a number joins them together as if both of them were strings.
7. What is the value of i after the following code runs?
1
2 var i = 7;
3 i += 1;
4 i += 2;
5
- 7
- 8
- 9
- 10 (Correct)
Correct: 1 is added to i and the result is stored in i . The value is now 8. Then, 2 is added to i and the result is stored in i . The value is now 10 .
SELF REVIEW: PRACTICE CONDITIONAL STATEMENTS
1. Did you complete the Practice conditional statements exercise?
- Yes (Correct)
- No
Correct: Well done on completing the exercise!
2. Were there any parts of the Practice conditional statements exercise that you found difficult to complete?
- Yes (Correct)
- No
Correct: If you’ve found any particular part of the exercise as being difficult to complete, think about why that was the case. What was the hardest part of the task? Pin-pointing the most difficult concept will help you understand areas that potentially need to be worked on more.
3. Would you say that you are able to explain, in your own words, how an if statement and a switch statement work in JavaScript?
- Yes (Correct)
- No
Correct: Great! Being able to describe newly-learned concepts in your own words is a reflection of a better understanding of the subject matter.
SELF REVIEW: REPETITIVE TASKS WITH LOOPS
1. Did you complete the Repetitive tasks with loops exercise?
- Yes (Correct)
- No
Correct: Well done on completing the exercise!
2. Were there any parts of the Repetitive tasks with loops exercise that you found difficult to complete?
- Yes (Correct)
- No
Correct: If you’ve found any particular part of the exercise as being difficult to complete, think about why that was the case. What was the hardest part of the task? Pin-pointing the most difficult concept will help you understand areas that potentially need to be worked on more.
3. Would you say that you are able to explain, in your own words, what does the i++ do?
- Yes (Correct)
- No
Correct: Great! Being able to describe newly-learned concepts in your own words is a reflection of a better understanding of the subject matter.
4. Are you able to explain, in your own words, the syntax of a for loop in JavaScript?
- Yes (Correct)
- No
Correct: Great! Being able to describe newly-learned concepts in your own words is a reflection of a better understanding of the subject matter.
SELF REVIEW: WORKING WITH CONDITIONALS AND LOOPS
1. Did you complete the Working with conditionals and loops exercise?
- True (Correct)
- False
Correct: Well done on completing the exercise!
2. Were there any parts of the Working with conditionals and loops exercise that you found difficult to complete?
- True (Correct)
- False
Correct: If you’ve found any particular part of the exercise as being difficult to complete, think about why that was the case. What was the hardest part of the task? Pin-pointing the most difficult concept will help you understand areas that potentially need to be worked on more.
3. Would you say that you are able to explain, in your own words, how to code for loops and switch statements in JavaScript?
- True (Correct)
- False
Correct: Great! Being able to describe newly-learned concepts in your own words is a reflection of a better understanding of the subject matter.
KNOWLEDGE CHECK – CONDITIONALS AND LOOPS
1. Based on the following code, what will print out when the variable i has the value 3 ?
if(i < 5) {
console.log("Hello");
} else {
console.log("Goodbye");
}
- Hello (Correct)
- Goodbye
Correct: That’s correct! The code inside the if statement will execute because the condition i < 5 is true.
2. Based on the following code, what will print out when the variable i has the value 1 ?
if(i == 0 && i == 1) {
console.log("Hello");
} else {
console.log("Goodbye");
}
- Hello
- Goodbye (Correct)
Correct: The condition checks if i is equal to 0 AND 1 . Since it is not possible for i to be both values at the same time, the result of this check is false. Therefore, the code inside the else statement will run.
3. How many times will the following code print the word ‘Hello’?
for (i = 0; i < 2; i++) {
console.log("Hello");
}
- 1
- 2 (Correct)
- 3
- 4
Correct: That’s correct! The loop will run twice based on the condition i < 2 .
4. How many times will the following code print the word ‘Hello’?
var i = 0;
while(i < 3) {
console.log("Hello");
i++;
}
- 1
- 2
- 3 (Correct)
- 4
Correct: The loop will run 3 times based on the condition i < 3 .
5. How many times will the following code print the word ‘Hello’?
for (i = 0; i < 2; i++) {
for (var j = 0; j < 3; j++) {
console.log("Hello");
}
}
- 2
- 3
- 4
- 6 (Correct)
Correct: Remember that the inner loop will be run each time the outer loop runs.
6. Based on the following code, what will print out when the variable i has the value 7 ?
if(i <= 5) {
console.log("Hello");
} else if(i <= 10) {
console.log("Goodnight");
} else {
console.log("Goodbye");
}
- Hello
- Goodnight (Correct)
- Goodbye
Correct: That’s correct! The code inside the else if statement will execute. The first condition fails because the value of i is greater than 5. The second condition succeeds because the value of i is less than 10.
7. Based on the following code, what will print out when the variable i has the value 3 ?
switch(i) {
case 1:
console.log("Hello");
break;
case 2:
console.log("Goodnight");
break;
case 3:
console.log("Goodbye");
break;
}
- Hello
- Goodnight
- Goodbye (Correct)
Correct: The code for case 3 will run Goodbye.
8. Based on the following code, what will print out when the variable i has the value 3 ?
if(i == 2 || i == 3) {
console.log("Hello");
} else {
console.log("Goodbye");
}
- Hello (Correct)
- Goodbye
Correct: The condition checks if i is equal to 2 OR 3 . Since the value of i is 3 , the code inside the if statement will run.
9. The zeros and ones of binary code is a low-level language because it’s closer to being understood by a CPU. JavaScript on the other hand is a high-level language. This means that it has to be converted to binary code so that a CPU can work with it.
- Yes (Correct)
- No
Correct: Yes, that’s correct! As a high-level language, JavaScript does need to be converted to binary code so that a CPU can work with it.
10. You are building a website using JavaScript. On which end of the site will JavaScript add interactivity to?
- Front-end (Correct)
- Back-end
Correct: Yes, JavaScript adds interactivity to the front-end, or client-side, of a webpage.
11. JavaScript is integral to our everyday online experiences. Which of the following statements are true? Choose all that apply.
- JavaScript can provide a native feel to apps. (Correct)
- JavaScript can’t communicate with databases.
- Using JavaScript and React Native developers can create mobile apps. (Correct) JavaScript is used to power websites. (Correct)
Correct: That’s correct! Using JavaScript developers can create an original user experience.
Correct: That’s correct! JavaScript isn’t limited to only being used in browsers. Developers can also create apps using it in conjunction with React Native.
Correct: That’s correct! JavaScript is after all often called the language of the web.
12. Which of the following are examples of valid strings? Choose all that apply.
- ‘Hello world’ (Correct)
- “Hello world” (Correct)
- Hello world
Correct: Correct. Strings must be enclosed in either single or double quotations.
Correct: Strings must be enclosed in either single or double quotations.
13. Which of the following are examples of logical operators? Check all that apply.
- Or (Correct)
- Multiplication
- Not (Correct)
- Subtraction
- And (Correct)
Correct: That’s correct! Or is a logical operator, not a math operator. That’s correct! Not is a logical operator, not a math operator. That’s correct! And is a logical operator, not a math operator.
14. If parentheses are not used in a mathematical calculation JavaScript will …
- Follow the sequence the calculation is in from left to right.
- Follow the standard mathematical sequence of calculation. (Correct)
- Add all variables first.
Correct: That’s right! If parentheses are not used in a mathematical calculation, JavaScript will follow the standard mathematical sequence of calculation.
15. String literals are used to create string values in JavaScript. Which of the following are string literals? Select all that apply.
- Backticks
- Single quotation marks (Correct)
- Double quotation marks (Correct)
Correct: Correct! You can use single or double quotation marks to make a string literal.
16. There are various uses of the Boolean data type, one of which is to compare various values and types and it is used in conjunction with various operators such as the strict equality operator. True or false: the strict equality operator only checks for value and not type as well.
- True
- False (Correct)
Correct: That’s correct! The strict equality operator which is three equal signs is used to check for value and type.
17. True or false: An if statement can be used to run code based on a condition being true.
- True (Correct)
- False
Correct: Yes, an if statement can be used to run code based on a condition being met.
18. You need to execute code based on a certain condition being either true or false. Which of the following types of statements can you use to complete this task? Select all that apply.
- A for loop
- A switch statement (Correct)
- A conditional statement (Correct)
Correct: Correct! A switch statement can be used to execute code based on a certain condition being either true or false. A conditional statement can be used to execute code based on a certain condition being either true or false.
19. You need to execute repeated blocks of JavaScript code until a certain condition is satisfied. Can you perform this action using loops?
- No
- Yes (Correct)
Correct: Yes, JavaScript developers use loops to continually execute repeated blocks of code until a certain condition is satisfied.
20. How many lines will the loop below print in the console?
for (var i = 0; i <= 3; i++) {
console.log("This is line ", i)
}
- 0
- 1
- 2
- 3
- 4 (Correct)
Correct: That is correct. The loop iterates 4 times, from zero to 3.
21. True or false: A while loop will keep looping through a code block as long as a specified condition is true?
- False
- True (Correct)
Correct: A while loop will keep looping through a code block as long as a specified condition is true.
22. You are running multiple nested loops within your JavaScript code. Could these nested loops cause performance issues with your code?
- No
- Yes (Correct)
Correct: The more nested loops there are, the slower your code will run.
Additional JavaScript Operators
- Logical AND operator: &&
- Logical OR operator: ||
- Logical NOT operator: !
- The modulus operator: %
- The equality operator: ==
- The strict equality operator: ===
- The inequality operator: !=
- The strict inequality operator: !==
- The assignment operator: =
- The addition assignment operator: +=
- The concatenation assignment operator: +=
Coursera Meta Front-End Developer Professional Certificate Answers and Study Guide
Liking our content? Then don’t forget to ad us to your bookmarks so you can find us easily!
Weekly Breakdown | Meta Study Guides | Back to Top
MODULE QUIZ: INTRODUCTION TO JAVASCRIPT
1. You can run JavaScript in a web browser’s devtools console.
- No (Correct)
- Yes
Correct: The devtools console is useful for running JavaScript code.
2. Which of the following are valid comments in JavaScript? Select all that apply.
1
2 \ Comment 1
3
1
2 // Comment 2 (Correct)
3
1
2 ##
3 ## Comment 3
4 ##
5
1
2 /*
3 * Comment 4 (Correct)
4 */
5
Correct: That’s correct! // is used for inline comments. That’s correct! /* and */ are define the beginning and end of multi-line comments.
3. Which of the following are valid data types in JavaScript? Select all that apply.
- String (Correct)
- Numbers (Correct)
- Booleans (Correct)
- Null (Correct)
Correct: That’s correct! The string data type represents a sequence of characters in JavaScript.
Correct: That’s correct! Numbers represent both integer and decimal point numeric values.
Correct: That’s correct! The boolean data type has one of two values; true or false.
Correct: That’s correct! The null data type represents the absense of a value.
4. Which of the following is the logical AND operator in JavaScript?
- &
- && (Correct)
- ||
- |\
Correct: That’s correct! && is the logical AND operator used for condition checks.
5. Which of the following is the assignment operator in JavaScript?
- = (Correct)
- ==
- ===
Correct: That’s correct! The = symbol is used to assign to variables in JavaScript.
6. How many times will the following code print the word ‘Hello’?
for(var i = 0; i <= 5; i++) {
console.log("Hello");
}
- 4
- 5
- 6 (Correct)
Correct: That’s correct! ‘i’ starts with the value ‘0’. The condition checks if ‘i’ is less than or equal to ‘5’. Each loop increments ‘i’ by ‘1’. This means that the loop will run 6 times.
7. What will print out when the following code runs?
var i = 3;
var j = 5;
if(i == 3 && j < 5) {
console.log("Hello");
} else {
console.log("Goodbye");
}
- Hello
- Goodbye (Correct)
Correct: The condition checks if ‘i’ is equal to ‘3’ AND if ‘j’ is less than ‘5’. Since the result of this condition is false, the code inside the else statement will run.
8. What will print out when the following code runs?
var i = 7;
var j = 2;
if(i < 7 || j < 5) {
console.log("Hello");
} else {
console.log("Goodbye");
}
- Hello (Correct)
- Goodbye
Correct: That’s correct! The condition checks if ‘i’ is less than ‘7’ OR if ‘j’ is less than ‘5’. Since the result of this condition is true, the code inside the if statement will run.
9. The result of !false is:
- true (Correct)
- undefined
Correct: When you add the NOT operator before a Boolean value, the returned value is the opposite of the boolean value. Thus, !false is evaluated to true, and !true is evaluated to false.
10. What does the operator symbol || represent in JavaScript?
- The logical OR operator (Correct)
- The logical NOT operator
- The logical AND operator
Correct: That’s correct. In JavaScript, the || is the logical OR operator.
Introduction to JavaScript CONCLUSION
After completing this module, you will have a solid understanding of JavaScript and its importance in software development. You will also know how to write code inside the browser and understand common operators, conditional statements, and loops. These skills are essential for any software developer. If you’re interested in learning more about JavaScript and becoming a software developer, join Coursera now!
With Coursera, you can learn at your own pace from top universities and organizations around the world. So what are you waiting for? Enroll today!
Subscribe to our site
Get new content delivered directly to your inbox.
Quiztudy Top Courses
Popular in Coursera
- Meta Marketing Analytics Professional Certificate.
- Google Digital Marketing & E-commerce Professional Certificate.
- Google UX Design Professional Certificate.
- Meta Social Media Marketing Professional Certificate
- Google Project Management Professional Certificate
- Meta Front-End Developer Professional Certificate
Liking our content? Then, don’t forget to ad us to your BOOKMARKS so you can find us easily!