All Coursera Quiz Answers

Programming Assignment: Little Lemon Receipt Maker Solution

In this article i am gone to share Programming with JavaScript by meta Week 5 | Programming Assignment Little Lemon Receipt Maker Solution with you..

Enroll Link: Programming with JavaScript

Visit this link:ย  Programming Assignment: Writing a Unit Test Solution


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 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 Coursera

To 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:

  1. The stringย "Dish: "

  2. The value of currently looped-over dish object’s name property

  3. The stringย "Price: $"

  4. 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?

Programming Assignment: Little Lemon Receipt Maker Solution

  • Copy & paste this code on Files..
  • And save your file and then submit.

Change in this file finalProject.js

// 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!");
        console.log(`Dish: ${} Price: $${finalPrice}`);

// Implement getDiscount()
function getDiscount(taxBoolean, guests) {
    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)