6

Calculator Function using JavaScript ๐Ÿš€๐Ÿš€

 3 years ago
source link: https://dev.to/dev_shubham/calculator-function-using-javascript-22n0
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Cover image for Calculator Function using JavaScript ๐Ÿš€๐Ÿš€

Calculator Function using JavaScript ๐Ÿš€๐Ÿš€

Sep 18

ใƒป1 min read

How to create calculator function in JavaScript??

Yes, Today we are making a JavaScript function which is return some mathematics output.

So, let's start with JavaScript code.

(1) Let's make a JavaScript
file and give any name
here I am giving index.js.
(Note:- We must need a
html file to run our JS
code in browser)

(2) Next step make a function
name calculator() in js
file. And pass three
parameter x, y and o.

(3) Parameters explanation :-
(a) x is a first number
(b) y is a second number
(c) o is a operator

(4) We are using switch
statement as shown in
following code.

(4) Let's understand above
code :-
(a) first pass o
parameter because it
will decide which
mathematics operation
will conduct. o is
String and x and y
number
(b) If any user call this
function by passing three
parameters like
calculator(2,3,'+') then
the first case is
executed.
(c) When anyone not enter
valid input the it will
return "enter valid
numbers".

(5) Let's call the above
function and see output.

๐Ÿ‘‰ Happy Coding...
๐Ÿ™ Thank you for reading...


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK