Ellioty15 / Elliot_2025

Apache License 2.0
0 stars 0 forks source link

3.3, 3.5 hacks Elliot Yang #6

Open Ellioty15 opened 1 month ago

Ellioty15 commented 1 month ago

Booleans hack function goOutside(temperature, isRaining) { if (temperature < 100 && isRaining === true) { return true; } else if (temperature > 32 && isRaining === false) { return true; } else { return false; } }

Hack #1 // Addition function with parameters function add(a, b) { return a + b; }

// Subtraction function with parameters function subtract(a, b) { return a - b; }

// Division function with denominator check function divide(numerator, denominator) { if (denominator === 0) { return "Cannot have a denominator of 0"; } return numerator / denominator; }

// Modulus function with parameters function modulus(a, b) { return a % b; }

// Power function corrected with parameters function power(base, exponent) { return base ** exponent; }

Hack #2 %%javascript

// Function to find the y value on the graph of f(x) = 5x + 2 function findY(x) { return 5 * x + 2; // return the result based on the input x }

// Example usage: change x_value to whatever you want let x_value = 2; // Assigning 2 to x_value let y_value = findY(x_value); // Calling the function to get the y value

// Output the result console.log(For x = ${x_value}, the y value is: ${y_value});

Hack #3 function findPoint(x) { // f(x) = 5x + 2, which is equivalent to y = mx + b const m = 5; const b = 2;

// Calculate y value for the given x
const y = m * x + b;

return y;

}

Hack #4 // Original expression let stayInside = !(isRaining && isCold);

// Using De Morgan's Law: !(A && B) === !A || !B let stayInside = !isRaining || !isCold;

// Original expression let stayInside = !(isRaining || isCold);

// Using De Morgan's Law: !(A || B) === !A && !B let stayInside = !isRaining && !isCold;

WyattZCSP commented 1 month ago

Hey Elliot, When you create a function, the parameters are meant to be variables. For example for a dividing function you would use the variables:

def divide (numerator, denominator)
  if denominator == 0:
    return "Cannot have a denominator of 0"
  return numerator / denominator

Doing this allows you to divide whateber numbers you would like to be the numerator and denominator.

divide(100, 50)
divide(2, 5)