Professional Documents
Culture Documents
function displayValues(values){
values.forEach(value => {
console.log(value**3);
})
}
/*
3. Write a function called areAllEven that takes an array of numbers as input
and returns a boolean which determines if all the numbers given are even or not.
- Create a new variable inside the function called isEven.
- Use the every() method to check if all the numbers are even and save the
result into the variable.
T - Return the isEven variable.
*/
// function areAllEven(numbers) {
// return numbers.every(function(number) {
// return number % 2 === 0;
// });
// }
function areAllEven(numbers) {
let isEven = numbers.every(function(number) {
return number % 2 === 0;
});
return isEven;
}
/*
4. Write a function called hasDivisibleBy8 that takes an array of numbers as
input returns a boolean which determines if the array contains at least one number
divisible by 8.
- Create a new variable called hasDivisible
- Use the some() method to check if at least one of the given values is
divisible by 8, save the result in the hasDivisible variable.
- Return the hasDivisible variable.
*/
function hasDivisibleBy8(numbers){
let hasDivisible = numbers.some(number => {
return number % 8 === 0;
})
return hasDivisible;
}
/*
5. Write a function called filterEvenNumbers that takes an array of numbers as
input and returns a new array containing only the even numbers from the original
array.
- Create a new variable called filteredNum
- Use the filter() method to create a new array of only the even numbers
from the original array save it in the filteredNum variable.
- Return the filteredNum variable.
*/
function filterEvenNumbers(numbers){
let filteredNum;
filteredNum = numbers.filter(number => {
return number % 2 === 0;
})
return filteredNum;
}
} catch(err){