Skip to content

Instantly share code, notes, and snippets.

@McLarenCollege
Last active January 18, 2022 06:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McLarenCollege/9ae8a9c0503ae36db416eaf6319ff795 to your computer and use it in GitHub Desktop.
Save McLarenCollege/9ae8a9c0503ae36db416eaf6319ff795 to your computer and use it in GitHub Desktop.
Calculator
/*
You are required to create a simple calculator that returns the result of addition, subtraction, multiplication or division of two numbers.
Your function will accept three arguments:
The first and second argument should be numbers.
The third argument should represent a sign indicating the operation to perform on these two numbers.
if the sign does not belong to the list above a message "unknown operator" must be returned.
*/
// Example:
calculator(1,2,"+"); //=> result will be 3
calculator(1,2,"&"); //=> result will be "unknown operator"
calculator(1,2,"*"); //=> result will be 2
calculator(4,2,"/"); //=> result will be 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment