Tuesday, May 4, 2021

Javascript Practice 27: JS Hero - Numbers

 
Question: 

Write a function add that takes two numbers and returns their sum.

Example: add(1, 2) should return 3.




Answer: 

function add (a,b) {

return a+b; 

}; 

> a simple function add is created
> it is returned with the sum of two parameters
> JavaScript uses the + operator for both addition and concatenation
> numbers are added & strings are concatenated

No comments:

Post a Comment