https://www.codewars.com/kata/57356c55867b9b7a60000bd7
Your task is to create a function that does four basic mathematical operations.
The function should take three arguments - operation(string/char), value1(number), value2(number).
The function should return result of numbers after applying the chosen operation.
(Operator, value1, value2) --> output
('+', 4, 7) --> 11
('-', 15, 18) --> -3
('*', 5, 5) --> 25
('/', 49, 7) --> 7
function basicOp(operation, value1, value2) {
let answer = 0;
switch (operation) {
case '+':
answer = value1 + value2;
break;
case '-':
answer = value1 - value2;
break;
case '*':
answer = value1 * value2;
break;
case '/':
answer = value1 / value2;
break;
}
return answer;
}
function basicOp(operation, value1, value2) {
var cases = {
'+': value1 + value2,
'-': value1 - value2,
'*': value1 * value2,
'/': value1 / value2
};
return cases[operation]
}Basic mathematical operations form the foundation of problem-solving in everyday life. Addition, subtraction, multiplication, and division are the primary tools that help organize numbers and manage calculations effectively. These operations also extend into more advanced concepts like fractions, percentages, and algebra. For students preparing for exams, mastering them is essential. Practicing consistently, especially through resources such as SAT Math practice strengthens accuracy and confidence. Whether balancing expenses, measuring quantities, or tackling academic challenges, fluency in these operations supports both practical needs and academic success.
Maths can be very useful in life, and also if you want to work in the IT field, for example. Now children can learn maths from early childhood thanks to platforms like Brighterly, where teachers will make the best math programs for kids, and also organize the learning process in such a way that it doesn't bother the child and will be effective.