DEV Community

davidka7
davidka7

Posted on

How to write a simple javascript algorithm, for javascript beginners.

Write A function, then call it underneath with the write arguments(the string/boolean/number/float/etc inside the function parenthesis). Then right punctuality inside a function and return the new data.

function addition(number) {
number = number + number
return number
// answer returned is 10
}

addition(5)

Top comments (1)

Collapse
 
shrihankp profile image
Shrihan • Edited

The code can be shortened to:

const addition = n => n*2;
addition(5)
Enter fullscreen mode Exit fullscreen mode

Also, its not a good practice to modify the function arguments directly.