Javascript Function Creation Question 10

Introduction

Define a function called add_numbers() that adds two numbers and throws an error if the arguments supplied to the function are not numbers.

function add_numbers(a, b) {
    //your code

}

console.log(add_numbers("fish", 138));


function add_numbers(a, b) {
    if (isNaN(a) || isNaN(b)) {
        return ("Please enter two valid numbers");
    } else {
        return (a + b);
    }

}

console.log(add_numbers("fish", 138));



PreviousNext

Related