You are on page 1of 6

Unit 07 Lesson 01 (Oly)

Name(s)_______Abdelrahman Marzouk________________ Period _4th Block____ Date ____3/23/2024

Activity Guide - Function Houses


Instructions:

Challenge #1: Time to create your own function with parameters!

● Create a function (javascript or pseudocode) with two parameters to draw a house.


○ Think about the parameters. How could your function be used to draw different types or
sizes of houses? Give each parameter a unique name.
○ When the parameter is referenced in the function, make it bold to draw attention. (2 pts)

Name Parameter 1 name Parameter 2 name

function drawHouse ( sides , size ){

Create 5 sides at the size of 10 ft


Cut 2 sides 4 feet short for correction in size
Assemble a U shape with the 3 longer sides.
Lastly add the 2 smaller sides at the top in a triangle shape.

● In the boxes below, show how you would call the function using different parameters (2 pts)

drawSmallerHouse; Change length for shorter sides and smaller house

● Draw what your function should do in the space below for each of the two function calls above. If
doing this in Google Docs, double-click the grid and use the line tools. (2 pts)

1
/
Challenge #2: Create a cost calculator function for building the houses you created a function for earlier.

● Create a 2nd function using the same parameters as the first function you wrote (2 pts) ○
Think about the parameters. How would these impact the cost?
○ When the parameter is referenced in the function, make it bold to draw attention. ○
Add a return at the end of your function that returns the total cost..
name Parameter 1 name Parameter 2 name

function houseCost ( sideLength , sizeCost ) {

1ft = 5$
If sideLength=10ft cost is 10$
Function: drawHouse cost = 42$
Function: drawSmallerHouse = 27$

}
● In the boxes below, show how you would call the function using different parameters. (2
pts) ○ Show the expected return value for each function call in the right column.
Function calls Return Value

cost1 = drawHouse: starting Side length = 10; top side = 6 42$

cost2= drawSmallerHouse: startingLength= 7; top side = 3 27$


// Function to calculate the cost of building a house
function calculateHouseBuildingCost(squareFeet, numBedrooms, numBathrooms, qualityOfMaterials) {
// Base price per square foot depending on the quality of materials
const basePricePerSquareFoot = {
standard: 100,
premium: 150,
luxury: 200
};

// Additional cost per room


const costPerBedroom = 10000;
const costPerBathroom = 5000;

// Calculate the total cost


const baseCost = squareFeet * basePricePerSquareFoot[qualityOfMaterials];
const bedroomsCost = numBedrooms * costPerBedroom;
const bathroomsCost = numBathrooms * costPerBathroom;
const totalCost = baseCost + bedroomsCost + bathroomsCost;

// Return the total cost


return totalCost;
}

// Example usage:
// A 2000 square feet house with 3 bedrooms, 2 bathrooms, using premium materials
const costOfMyHouse = calculateHouseBuildingCost(2000, 3, 2, 'premium');
console.log('The cost to build your house is: $' + costOfMyHouse);
// This will output something like:
// "The cost to build your house is: $330000"

Warm Up:
Making your code easier to work with or read enhances maintainability, facilitates collaboration, and accelerates
debugging and future development.
Activity:
A four-layer chocolate cake would consist of four individual cake layers stacked on top of each other, each separated
by a layer of frosting or filling. The outside of the cake could be covered with more chocolate frosting, smoothed or
textured as per your preference. For decoration, you might see chocolate shavings, chocolate pieces, or other
adornments on top. Would you like to see a visual representation of such a cake?

You might also like