daily pastebin goal
25%
SHARE
TWEET

Untitled

a guest Dec 14th, 2017 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Programming Quiz: Another Type of Loop (6-8)
  3.  *
  4.  * Use the existing `test` variable and write a `forEach` loop
  5.  * that adds 100 to each number that is divisible by 3.
  6.  *
  7.  * Things to note:
  8.  *  - you must use an `if` statement to verify code is divisible by 3
  9.  *  - you can use `console.log` to verify the `test` variable when you're finished looping
  10.  * Use the array's forEach() method to loop over the following array and add 100 to each of the values if the value is divisible by 3.
  11.  */
  12.  
  13. var test = [12, 929, 11, 3, 199, 1000, 7, 1, 24, 37, 4,
  14.     19, 300, 3775, 299, 36, 209, 148, 169, 299,
  15.     6, 109, 20, 58, 139, 59, 3, 1, 139
  16. ];
  17.  
  18. // Write your code here
  19. test.forEach(function(num,index){
  20.     if(num % 3 === 0){
  21.         test[index] += 100;
  22.     }
  23. });
  24.  
  25. console.log(test);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top