In the final module, you’ll synthesize the skills you gained from the course to create code for the “Little lemon receipt maker. After you complete the individual units in this module, you will be able to take the graded assessment. You’ll also have to opportunity to reflect on the course content and the learning path that lies ahead.
Learning Objectives
Revise conditional statements, for loops, looping over arrays of objects, comparison operators, booleans, strings, numbers, arithmetic operators.
End-of-Course Graded Assessment
Video: Recap Programming with JavaScript
- Real-world applications and job opportunities related to JavaScript
- How to install VS code on Windows for coding in JavaScript
- The importance of JavaScript in programming and the different libraries used by JavaScript developers
- Key concepts in JavaScript, such as variables, data types, math and logical operators, strings, and Booleans
- Conditionals and loops, including different types of conditional statements and loops like for, while, and nested loops
- Building blocks of a program, including arrays, objects, and functions
- Error prevention, recognizing bugs and errors, try-catch blocks, and understanding undefined, null, and empty string values
- Programming paradigms, such as functional programming and object-oriented programming
- Advanced JavaScript features like destructuring arrays and objects, for-of loops, template literals, and spread and rest operators
- Manipulating JavaScript in the browser, working with the DOM, interactivity, events, and data manipulation
- Testing and compatibility, including different types of testing, writing unit tests with Jest, and test-driven development
In this course,
you discovered how to program with JavaScript. Let’s take a few minutes
to recap what you learned. In the opening module, you discovered real-world
applications of JavaScript and uncovered
possible job opportunities. You also learned how to install VS code on Windows so that
you could code in JS. You did learned about the
importance of JavaScript in programming and the
different libraries used by JavaScript developers. As you progress
through the lesson, you encountered key
concepts in JavaScript. By engaging with
these concepts you discovered how to identify
and declare variables, differentiate
between data types, and recognize math and
logical operators. You also learned how to
perform basic arithmetic using the number data type and
utilize strings and Booleans. In the next lesson, you explored
conditionals and loops. During your exploration
of these concepts, you learned how to script
different forms of JavaScript conditional statements and work with different types of loops, such as for, while, and nested. In Module 2 you explored the building
blocks of a program. You began this
module with a lesson on arrays, objects,
and functions. During this lesson you
learned how to explain the purpose of functions and
describe their benefits, outline the process for building an array and accessing
its contents, and you now understand the array characteristics and concatenation
operators of strings, and you can now also
build and call functions, create custom objects, explain how math objects work, and interact with
arrays and objects. You then moved onto the
next lesson in which you explored the concept
of error prevention. During this lesson,
you discovered how to recognize the differences
between bugs and errors, demonstrate try-catch blocks, and explain the
concepts of undefined, null and empty string values. The next module on
programming paradigms began with the lesson on
functional programming, in which you learned how to explain how the functional
paradigm works, outline the concept
of recursion, describe how scope operates, and explain different
forms of scope such as let, const, and var. In the next lesson, you explored object
oriented programming and learned the principles of
object oriented programming, how to deploy classes
in JavaScript, build and utilize constructors, and make use of inheritance. You then explored advanced
JavaScript features in which you learned how to
destruct arrays and objects, utilized for-of
loops and objects, explain the concepts of template literals
and data structures, and demonstrate the use of the
spread and rest operators. Finally, you then explored how JavaScript operates
in the browser. During this lesson,
you learned how to manipulate JavaScript
in the DOM, make use of JavaScript
interactivity in the browser, work with events, and capture and move
data around the web. In the next module, you looked at testing
and compatibility. The lesson began
with an introduction to testing in which
you learned about the concept of testing and how to practice different
types of testing, how to write a unit test, the process for writing
tests with Jest, and how to apply
test-driven development. You then reviewed JavaScript testing challenges
in which you learned how to navigate other JS
environments like Node and NPM, the concepts of webpack
and transpiring, the process for working with arrow functions and
classes in React, and you discovered the role the DOM plays in
testing challenges, and finally, you discovered
how to write tests with Jest. Well done on
completing this recap. Now it’s time to
try out what you’ve learned in the graded
assessment. Good luck.
Reading: Programming Assignment: Little Lemon Receipt Maker
Reading
Lab Instructions: Little Lemon Receipt Maker
Tips: Before you Begin
To view your code and instructions side-by-side, select the following in your VSCode toolbar:
- View -> Editor Layout -> Two Columns
- To view this file in Preview mode, right click on this README.md file and
Open Preview
- Select your code file in the code tree, which will open it up in a new VSCode tab.
- Drag your assessment code files over to the second column.
- Great work! You can now see instructions and code at the same time.
- Questions about using VSCode? Please see our support resources here:
Visual Studio Code on CourseraTo run your JavaScript code
- Select your JavaScript file
- Select the “Run Code” button in the upper right hand toolbar of VSCode.
Ex: It looks like a triangular “Play” button.
Assignment Instructions
In this exercise, you will work with some data provided as an array of objects, listing information about dishes available in the Little Lemon restaurant.
Step 1: In the function getPrices()
, give it the parameter of taxBoolean
.
Step 2: Inside the getPrices()
function, code a for loop that will loop over all the objects inside the dishData
array.
Step 3: Inside the for loop, declare a finalPrice
variable, without assigning it a value.
Step 4: Still inside the for loop, add an if condition, checking that the taxBoolean
is set to true
. Inside the if block, multiply the following: * the price of the currently looped-over object from the dishData
array, and * the tax value. Assign the multiplied value to the finalPrice variable.
Step 5: Right after the if condition, add an else if, checking if the value of taxBoolean
is false. Inside this condition’s block, assign the currently looped-over dish price property in the dishData
array to the finalPrice
variable.
Step 6: Code the else
case, and inside of it, add two lines of code:
A console log of the string:
- “You need to pass a boolean to the getPrices call!”
- return (to “jump out” of the further function execution)
Step 7: After all the conditional’s statements, but still inside the for loop, code another console log with four arguments:
- The string
"Dish: "
- The value of currently looped-over dish object’s name property
- The string
"Price: $"
- The value of the
finalPrice
variable
Step 8: You’re finshed with the getPrices()
function, and now you’re ready to code another function. Give the getDiscount()
function, two parameters: the taxBoolean
and the guests
parameter.
Step 9: Inside the getDiscount()
function, on the very first line of its body, invoke the getPrices()
function, passing it the taxBoolean
as an argument.
Step 10: On another line, you need to implement your defensive coding skills, and check that the type of the guests
parameter is ‘number’ and that the value of the guests variable is greater than zero and less than 30. If all these conditions return true, code the body of the conditional as described in the next step. If they don’t all return true, code the body of the else conditional as instructed in step 12.
Step 11: Inside the if statment, declare a new variable, named discount
, and set it to 0. On the next line, add another if…else if: in the first if, you’ll check that the value of the guests
variable is less than 5. If that’s the case, reassign the value of the discount variable to 5;
- Inside the else if condition, check that the value of the guests variable is greater than or equal to 5 – if that’s the case, reassign the discount variable to 10.
- Console log the following after closing your else-if statement:
'Discount is: $' + discount);
Step 12: In the else condition, console log the following string: 'The second argument must be a number between 0 and 30'
. Since you’ve finished declaring both the getPrices()
and the getDiscount()
functions, you can now invoke the getDiscount()
function several times, with various combinations of arguments, to check the behavior.
Here are two examples:
getDiscount(true, 2)
getDiscount(false, 10)
What happens when you don’t pass-in any arguments?
What happens when you pass values that are not expected?
Code
// Given variables
const dishData = [
{
name: "Italian pasta",
price: 9.55
},
{
name: "Rice with veggies",
price: 8.65
},
{
name: "Chicken with potatoes",
price: 15.55
},
{
name: "Vegetarian Pizza",
price: 6.45
},
]
const tax = 1.20;
// Implement getPrices()
function getPrices(taxBoolean) {
for (var dish of dishData) {
var finalPrice;
if (taxBoolean===true) {
finalPrice = dish.price * tax;
} else if(taxBoolean===false){
finalPrice = dish.price;
} else {
console.log("You need to pass a boolean to the getPrices call!");
return;
}
console.log(`Dish: ${dish.name} Price: $${finalPrice}`);
}
}
// Implement getDiscount()
function getDiscount(taxBoolean, guests) {
getPrices(taxBoolean);
if (guests > 0 && guests < 30) {
var discount = 0;
if (guests < 5) {
discount = 5;
} else if (guests >= 5) {
discount = 10;
}
console.log(`Discount is: $${discount}`)
} else {
console.log('The second argument must be a number between 0 and 30');
}
}
// Call getDiscount()
getDiscount(true, 2)
getDiscount(false, 10)
Quiz: Final graded quiz: Programming with JavaScript
What will be the output of the following JavaScript?
const a = 10;
const b = 5;
if(a == 7 || b == 5) {
console.log("Green");
} else {
console.log("Blue");
}
Green
That’s correct. The logical OR operator results in the condition being true. Therefore, the code inside the if statement will execute and Green will be output.
What will be the output of the following JavaScript?
var x = true;
x = 23;
console.log(x);
23
That’s correct! The x variable is re-assigned the value 23. Therefore, 23 is output by the code.
What is the data type of the x variable in the following code?
var x = 0 != 1;
Boolean
That’s correct! 0 != 1 will result in a true value which is a boolean.
What will the following JavaScript code output?
var x = 20;
if(x >= 10) {
console.log("Apple");
} else if(x <= 5) {
console.log("Pear");
} else {
console.log("Orange");
}
Apple
That’s correct! The x variable has the value of 20, therefore the first condition succeeds. The code inside the if statement will run and output Apple.
What will the following JavaScript code output?
var result = 0;
for(var i = 0; i < 5; i++) {
result += 2;
}
console.log(result);
10
That’s correct! The loop will run 5 times and each time add 2 to the result variable. Therefore, 10 will be output.
What will the following JavaScript code output?
var result;
console.log(result);
result = 7;
7
What’s missing from this JavaScript function declaration?
function(a,b) {
return a + b
}
The function name.
Well done. When coding function declarations, you need to give them a name.
What is the output of the code below?
var car = { mileage: 200 }
var carMileage = 100
console.log(car.mileage)
200
Well done. You can access the mileage property on the car object using the dot notation.
What is the output of the code below?
var veggies = ['parsley', 'carrot']
console.log(veggies[2])
undefined
Well done. Trying to output the third item in the veggies array, using the syntax veggies [2] will console log undefined because the veggies array has only 2 items, “parsley” and “carrot”.
What is the first argument passed to the addEventListener function?
A string describing the type of event (such as, “click”).
Well done. The first argument to pass to the addEventListener function is the type of the event you’re listening for, such as “click”.
How do you create a new h2 element using JavaScript?
With document.createElement(‘h2’)
Well done. You create new elements on the document object using the createElement function.
What does this code do?
function addFive(val) {
return val + 5;
};
module.exports = addFive;
It defines the addFive function and exports it as a Node module so that it can be used in other files.
Well done. It’s a way to export the addFive function as a module that can be used elsewhere.
Course wrap up
Video: Congratulations on completing the course Programming with JavaScript
This text summarizes the key skills learned in a JavaScript programming course.
Skills Learned:
- Introduction to Programming:
- Explain capabilities and uses of JavaScript.
- Describe background and history of JavaScript.
- Explain importance of ECMA and ECMAScript.
- Describe JavaScript libraries and their uses.
- Core Concepts:
- Code single-line and multi-line comments.
- Use variables, data types, operators, numbers, Booleans, and strings.
- Programming Techniques:
- Write statements using conditionals and loops.
- Use arrays, objects, and functions.
- Implement error prevention in code.
- Programming Paradigms:
- Understand functional programming and object oriented programming.
- Advanced Features:
- Utilize advanced JavaScript features like destructuring, template literals, and spread/rest operators.
- JavaScript in Browser:
- Manipulate JavaScript in the DOM.
- Work with JavaScript interactivity and events.
- Testing and Compatibility:
- Explain the purpose of testing and explore different types.
- Understand JavaScript testing challenges and Jest testing.
Overall:
This course provides a comprehensive foundation for becoming a JavaScript developer. Congratulations on completing it!
Congratulations on completing the programming with
JavaScript course. You’ve worked hard to get here, and developed a lot of
new skills along the way. Let’s list some of the
key skills you’ve gained. You began with an
introduction to programming, and you should now
be able to explain the capabilities and
uses of JavaScript, describe the background
and history of JavaScript, explaining the importance
of ECMA and ECMAScript, and describe JavaScript
libraries and their uses. You did received
an introduction to core concepts of
JavaScript coding, and should now know how to code single-line and
multi-line comments with semicolon syntax and
using variables, data types, operators, numbers, Booleans, and strings. You further extended
your coding abilities by writing statements using
conditionals and loops, using arrays, objects
and functions, and enabling error
prevention in your code. Programming paradigms
introduced you to functional programming and
object oriented programming, advanced JavaScript features and the operation of
JavaScript in a browser. Finally, with testing
and compatibility, you discovered the
purpose of testing, explored types of testing, and studied JavaScript testing challenges and
testing with Jest. Congratulations once
again on reaching the end of this course on
programming in JavaScript. You’ve taken a valuable step on your journey toward
becoming a developer.