3.7.1 Hacks

# Popcorn Hack #1
weather = "sunny"
transportation = "available"    
boots = "not present"
location_determined = "yes"

print("The weather is " + weather)
print("Your transportation is " + transportation)
print("Your boots are " + boots)
print("Location determined: " + location_determined)

if weather == "sunny":
    if transportation == "available":
        if boots == "present":
            if location_determined == "yes":
                print("You are ready to go hiking!")
            else:
                print("You need to determine the location first.")
        else:
            print("You need to find your boots first.")
    else:
        print("You need to arrange transportation.")
else:
    print("It's not good weather for hiking.")
The weather is sunny
Your transportation is available
Your boots are not present
Location determined: yes
You need to find your boots first.

3.7.2 Hacks

// Popcorn Hack #2
let weather = "sunny";
let transportation = "available";
let boots = "present";
let locationDetermined = "yes";

console.log("The weather is " + weather);
console.log("Your transportation is " + transportation);
console.log("Your boots are " + boots);
console.log("Location determined: " + locationDetermined);

if (weather === "sunny") {
    if (transportation === "available") {
        if (boots === "present") {
            if (locationDetermined === "yes") {
                console.log("You are ready to go hiking!");
            } else {
                console.log("You need to determine the location first.");
            }
        } else {
            console.log("You need to find your boots first.");
        }
    } else {
        console.log("You need to arrange transportation.");
    }
} else {
    console.log("It's not good weather for hiking.");
}
3.7.3 Hacks
# Hack #1
weather = "sunny"
have_sunscreen = True
have_snacks = True

if weather == "sunny":
    if have_sunscreen:
        if have_snacks:
            print("You are ready for the beach!")
        else:
            print("You need to get snacks first.")
    else:
        print("You need to buy sunscreen.")
else:
    print("It's not a good day for the beach.")
# Hack #2
age = 20
space_in_sqft = 60
available_to_care = True

if age >= 18:
    if space_in_sqft > 50:
        if available_to_care:
            print("You can adopt the pet.")
        else:
            print("You need to make time to take care of the pet.")
    else:
        print("You need a bigger home.")
else:
    print("You must be at least 18 to adopt a pet.")
# Hack #3
weather = "clear"
have_running_shoes = True
days_practiced = 12

if weather == "clear":
    if have_running_shoes:
        if days_practiced >= 10:
            print("You are ready for the marathon.")
        else:
            print("You need to practice more.")
    else:
        print("You need to buy shoes first.")
else:
    print("It's not the right time for the marathon.")

3.7.4 Hacks

// Hack #1
let haveStudyMaterials = true;
let haveQuietPlace = true;
let feelingTired = false;

if (haveStudyMaterials) {
    if (haveQuietPlace) {
        if (!feelingTired) {
            console.log("You are ready to study.");
        } else {
            console.log("You need to take a nap or rest first.");
        }
    } else {
        console.log("You need to find a quiet place to study.");
    }
} else {
    console.log("You need to gather your study materials first.");
}
// Hack #2
let haveFlour = true;
let haveEggs = true;
let haveSugar = false;
let ovenWorking = true;
let timeAvailable = 3;

if (haveFlour && haveEggs && haveSugar) {
    if (ovenWorking) {
        if (timeAvailable >= 2) {
            console.log("You can start baking.");
        } else {
            console.log("You need to find more time.");
        }
    } else {
        console.log("You need to fix or replace the oven.");
    }
} else {
    let missingIngredients = [];
    if (!haveFlour) missingIngredients.push("flour");
    if (!haveEggs) missingIngredients.push("eggs");
    if (!haveSugar) missingIngredients.push("sugar");
    console.log("You are missing the following ingredients: " + missingIngredients.join(", "));
}
// Hack #3
let weather = "clear";
let haveTent = true;
let haveFoodAndWater = false;

if (weather === "clear") {
    if (haveTent) {
        if (haveFoodAndWater) {
            console.log("You are ready to go camping.");
        } else {
            console.log("You need to pack more food and water.");
        }
    } else {
        console.log("You need to buy or borrow a tent.");
    }
} else {
    console.log("It's not a good time for camping.");
}