I'm a complete newbie to programming and mathematical concepts (took Math 101 in college) so I'm struggling with this problem:
Write a function that takes in a number, and returns an array with that number in it that many times.
Here's the code I've got so far:
function numReturn(x) {
var newArray = [];
if (typeof x === "number") {
return newArray.push[x]* x;
} else {
return null;
}
}
Here's my thought process:
- Create a function that can take in a number, x.
- Within that function, create a blank array so you can push values to it later.
- Check if the
typeof
value entered in for x is a number. If it is, return it pushed to the end of the blank array. Otherwise, returnnull
.
When I put this in the Javascript console and plug a value in, it comes back undefined. Anyone have some pointers for me?