To view solutions, open the file /Day3/index.html
in your browser.
Do not forget to open the Developer panel and see the section Console
.
Task:
Complete the getSecondLargest
function in the editor below. It has one parameter: an array, nums
, of numbers.
The function must find and return the second largest number in nums
.
Solution:
In js/arrays.js
.
Task:
Complete the reverseString function; it has one parameter, s
. You must perform the following actions:
- Try to reverse string using the split, reverse, and join methods.
- If an exception is thrown, catch it and print the contents of the exception's
message
on a new line. - Print
s
on a new line. If no exception was thrown, then this should be the reversed string; if an exception was thrown, this should be the original string.
Solution:
In js/try-catch.js
.
Task:
Complete the isPositive function below. It has one integer parameter, a
. If the value of a
is positive, it must
return the string YES
. Otherwise, it must throw an Error according to the following rules:
- If
a
is0
, throw an Error with= Zero Error
. - If
a
is negative, throw an Error with= Negative Error
.
Solution:
In js/throw.js
.
Return to navigation list