function fizzbuzz(times) {
for (var i = 1; i <= times; i++) {
// you must test for both first
if (i % 5 === 0 && i % 3 === 0) {
console.log('FizzBuzz');
} else if (i % 5 === 0) {
console.log('Buzz');
} else if (i % 3 === 0) {
console.log('Fizz');
} else {
console.log(i);
}
}
}
fizzbuzz(100);
Last active
July 29, 2016 18:08
-
-
Save nkabrown/7919a0d2f99fcc3e1af04680498a9126 to your computer and use it in GitHub Desktop.
C4Q Access Code — Application Workshop
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Darleen,
I'll do a little bit with the adjacent elements question and leave the difference between any two elements to you.
So this is the question:
If we break that down we want to find the differences between all the adjacent elements in the array and save the largest difference to a variable that we will return from the function.
The pieces of code that we will need are a function, a variable to store the largest difference, a for loop that will iterate over the adjacent element pairs of the array, a return statement that will return the largest difference.
Note:
What happens if the first element is 4 and the second element is 11. 4 - 11 is -7. It's going to be hard to make a conditional test with both negative and positive numbers.
See this link for a method from the Math built-in object called abs() that will always return a positive number value: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs