Math Expressions: eliminating ambiguity Flashcards
calculatedNum = 2 + (2 * 6);
What is the value of calculatedNum?
14
calculatedNum = (2 + 2) * 6;
What is the value of calculatedNum?
24
calculatedNum = (2 + 2) * (4 + 2);
What is the value of calculatedNum?
24
calculatedNum = ((2 + 2) * 4) + 2;
What is the value of calculatedNum?
18
Write a statement that assigns to num the result of 10 + 2 * 4, clarified with parentheses, producing 18. The variable hasn’t been declared beforehand.
var num = 10 + (2 * 4);
Write a statement that assigns to cost the result of 2 + 2 * 4 + 10, clarified with parentheses, producing 56. The variable hasn’t been declared beforehand.
var cost = (2 + 2) * (4 + 10);
Write a statement that assigns to units the result of 2 + 2 * 4 + 10, clarified with parentheses, producing 20. The variable hasn’t been declared beforehand
var units = 2 + (2 * 4) + 10;
Write a statement that assigns to pressure the result of 4 / 2 * 4, clarified with parentheses, producing .5. The variable hasn’t been declared beforehand.
var pressure = 4 / (2 * 4);
Write a statement that assigns to pressure the result of 4 / 2 * 4, clarified with parentheses, producing 8. The variable hasn’t been declared beforehand.
var pressure = (4 / 2) * 4;
Write a statement that assigns to a variable the result of adding two variables together and then afterward multiplying the result of the addition by another variable. The first variable has been declared beforehand.
cost = (foodCost + laborCost) * multiplier;
Write a statement that assigns to a variable the result of 4 / 2 * 4 - 1, clarified with parentheses, producing -.5. The variable hasn’t been declared beforehand.
var x = (4 / (2 * 4)) - 1; or var x = 4 / (2 * 4) - 1;