Skip to content

Latest commit

 

History

History
48 lines (27 loc) · 1.37 KB

README.md

File metadata and controls

48 lines (27 loc) · 1.37 KB

10 Days of Javascript - Day 3

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.

Day 3: Arrays

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.

Day 3: Try, Catch, and Finally

Task:

Complete the reverseString function; it has one parameter, s. You must perform the following actions:

  1. Try to reverse string using the split, reverse, and join methods.
  2. If an exception is thrown, catch it and print the contents of the exception's message on a new line.
  3. 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.

Day 3: Throw

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 is 0, 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