33const getBiggest = ( x , y ) => {
44 // x and y are integers. Return the larger integer
55 // if they are the same return either one
6+ if ( x >= y ) {
7+ return x ;
8+ } return y ;
69} ;
710
811const greeting = ( language ) => {
@@ -11,15 +14,27 @@ const greeting = (language) => {
1114 // language: 'Spanish' -> 'Hola!'
1215 // language: 'Chinese' -> 'Ni Hao!'
1316 // if language is undefined return 'Hello!'
17+ switch ( language ) {
18+ case 'German' :
19+ return 'Guten Tag!' ;
20+ case 'Chinese' :
21+ return 'Ni Hao!' ;
22+ case 'Spanish' :
23+ return 'Hola!' ;
24+ default :
25+ return 'Hello!' ;
26+ }
1427} ;
1528
1629const isTenOrFive = ( num ) => {
1730 // return true if num is 10 or 5
1831 // otherwise return false
32+ return num === 10 || num === 5 ;
1933} ;
2034
2135const isInRange = ( num ) => {
2236 // return true if num is less than 50 and greater than 20
37+ return num < 50 && num > 20 ;
2338} ;
2439
2540const isInteger = ( num ) => {
@@ -29,13 +44,21 @@ const isInteger = (num) => {
2944 // -10 -> true
3045 // otherwise return false
3146 // hint: you can solve this using Math.floor
47+ return num === Math . round ( num ) ;
3248} ;
3349
3450const fizzBuzz = ( num ) => {
3551 // if num is divisible by 3 return 'fizz'
3652 // if num is divisible by 5 return 'buzz'
3753 // if num is divisible by 3 & 5 return 'fizzbuzz'
3854 // otherwise return num
55+ if ( num % 3 === 0 && num % 5 === 0 ) {
56+ return 'fizzbuzz' ;
57+ } else if ( num % 3 === 0 ) {
58+ return 'fizz' ;
59+ } else if ( num % 5 === 0 ) {
60+ return 'buzz' ;
61+ } return num ;
3962} ;
4063
4164const isPrime = ( num ) => {
@@ -44,62 +67,99 @@ const isPrime = (num) => {
4467 // hint: a prime number is only evenly divisible by itself and 1
4568 // hint2: you can solve this using a for loop
4669 // note: 0 and 1 are NOT considered prime numbers
70+ if ( num === 0 || num === 1 ) {
71+ return false ;
72+ } for ( let i = 2 ; i < num ; num ++ ) {
73+ if ( num % i === 0 ) {
74+ return false ;
75+ } return true ;
76+ }
4777} ;
4878
4979const returnFirst = ( arr ) => {
5080 // return the first item from the array
81+ return arr [ 0 ] ;
5182} ;
5283
5384const returnLast = ( arr ) => {
5485 // return the last item of the array
86+ return arr [ arr . length - 1 ] ;
5587} ;
5688
5789const getArrayLength = ( arr ) => {
5890 // return the length of the array
91+ return arr . length ;
5992} ;
6093
6194const incrementByOne = ( arr ) => {
6295 // arr is an array of integers
6396 // increase each integer by one
6497 // return the array
98+ for ( let i = 0 ; i < arr . length ; i ++ ) {
99+ arr [ i ] += 1 ;
100+ } return arr ;
65101} ;
66102
67103const addItemToArray = ( arr , item ) => {
68104 // add the item to the end of the array
69105 // return the array
106+ arr . push ( item ) ;
107+ return arr ;
70108} ;
71109
72110const addItemToFront = ( arr , item ) => {
73111 // add the item to the front of the array
74112 // return the array
75113 // hint: use the array method .unshift
114+ arr . unshift ( item ) ;
115+ return arr ;
76116} ;
77117
78118const wordsToSentence = ( words ) => {
79119 // words is an array of strings
80120 // return a string that is all of the words concatenated together
81121 // spaces need to be between each word
82122 // example: ['Hello', 'world!'] -> 'Hello world!'
123+ return words . join ( ' ' ) ;
83124} ;
84125
85126const contains = ( arr , item ) => {
86127 // check to see if item is inside of arr
87128 // return true if it is, otherwise return false
129+ for ( let i = 0 ; i < arr . length ; i ++ ) {
130+ if ( arr [ i ] === item ) {
131+ return true ;
132+ }
133+ } return false ;
88134} ;
89135
90136const addNumbers = ( numbers ) => {
91137 // numbers is an array of integers.
92138 // add all of the integers and return the value
139+ let sum = 0 ;
140+ for ( let i = 0 ; i < numbers . length ; i ++ ) {
141+ sum += numbers [ i ] ;
142+ } return sum ;
93143} ;
94144
95145const averageTestScore = ( testScores ) => {
96146 // testScores is an array. Iterate over testScores and compute the average.
97147 // return the average
148+ let sum = 0 ;
149+ for ( let i = 0 ; i < testScores . length ; i ++ ) {
150+ sum += testScores [ i ] ;
151+ } return sum / testScores . length ;
98152} ;
99153
100154const largestNumber = ( numbers ) => {
101155 // numbers is an array of integers
102156 // return the largest integer
157+ let largest = numbers [ 0 ] ;
158+ for ( let i = 1 ; i < numbers . length ; i ++ ) {
159+ if ( numbers [ i ] > largest ) {
160+ largest = numbers [ i ] ;
161+ }
162+ } return largest ;
103163} ;
104164
105165// Do not modify code below this line.
0 commit comments