Pastries and Logic Explainer

Explanation:

The aim of this puzzle:
Find a logic error in the function hasSupplies and fix it to give the correct output. This function is checking to see if we have both the ‘ingredients’ and an ‘appliance’ to bake them.

Walkthrough of the solution:
In JavaScript it is common to use logical operators to deal with the code’s logic; these include ‘and’ (&&), ‘or’ (||), and ‘not’ (!). hasSupplies begins in the Starter Code using the (||) operator, however, this means the function is checking if there is either ‘ingredients’ or ‘appliance’ when we should be checking that there are both ‘ingredients’ and ‘supplies’ with the (&&) operator.

Sample code solution:
(Tap below to reveal)

let readyToBake = 'You are ready to bake some pastries';
let needSupplies = 'Looks like you are missing something';

function hasSupplies(ingredients, appliance) {
    if (ingredients && appliance) {
        console.log(readyToBake);
    } 
}

hasSupplies('batter', 'oven');

JavaScript Concepts: Logical operators, function call, variable declaration, console.log, console