Skip to content

Instantly share code, notes, and snippets.

@McLarenCollege
Last active October 20, 2021 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McLarenCollege/ae84d2979c02ce2398aa61fdd3fc69f6 to your computer and use it in GitHub Desktop.
Save McLarenCollege/ae84d2979c02ce2398aa61fdd3fc69f6 to your computer and use it in GitHub Desktop.
Exercise Name : Print Until Negative using While loop

Given an array of numbers, loop through the array and print each number until you encounter a negative number. At the end, print the sum of all numbers traversed.

Note: use a while loop

For eg.

function printUntilNegative(numbers){
// write your code here
}
let numbers = [1,2,0,6,8,-1,2,-4];
printUntilNegative(numbers);

should print

1
2
0
6
8
17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment