Mathematical Operations in Javascript and Python - Hacks
Apply your skills of math, logic, and coding.
Basic Algebraic Math hacks
Q1 (Exponents):
A cube has a side length of 6 units. What is its volume?
%%js
let side = 6;
let volume = side ** 3;
console.log("The volume of the cube is: " + volume);
<IPython.core.display.Javascript object>
Q2 (PEMDAS):
Evaluate the expression:
(7+14)*5/12 + 2
%%js
// main function is not needed in JS, just run directly
console.log((7 + 14) * 5.0 / 12 + 2);
<IPython.core.display.Javascript object>
Q3 (Algorithm):
Write JavaScript code where you define variables and run commands that find the values of operations you apply onto them
%%js
// Define the numbers
let a = 7;
let b = 14;
let c = 5;
let d = 10;
let e = 2;
// Step 1: Add 7 + 14
let sum = a + b;
// Step 2: Multiply the sum by 5
let multiply = sum * c;
// Step 3: Divide the result by 10
let divide = multiply / d;
// Step 4: Add 2
let result = divide + e;
// Print the result
console.log("The final result is: " + result);
<IPython.core.display.Javascript object>
