can anyone one help me know to solve this...i am new to coding and i really confused.

  • using Swift or Javascript...
    Create a function called "timeAdder" that can add two time values together. For example, it should be able to add 25 hours and 3 days together.

    The function should accept 4 parameters:

    value1, label1, value2, label2

    • value1 and value2 should accept positive integers

    • label1 and label2 should accept any of the following strings: "seconds", "minutes", "hours", "days", "second", "minute", "hour", "day"

    For example your function may be called in any of the following ways:





    1. Your function should include at least one switch

    2. Your function must accept any possible combination of inputs

    3. If the inputs are valid, it should return a tuple with 2 variables inside of it: value3, and label3. For example:

    return (5,"minutes"). The exact label you choose to return for label3 ("minutes" for example) is up to you.

    1. If the inputs are invalid or impossible, it should return false. Here are examples of impossible and invalid inputs:

    timeAdder(5,"hour",5,"minutes") // This is impossible because "hour" is singular and 5 is plural

    timeAdder(false,false,5,"minutes") // This is invalid because the first 2 arguments are not the correct types

    timeAdder({},"days",5,"minutes") // This is invalid because the first argument is the wrong type

  • Hey @Mying-Humtsoe

    I decided to put my answer in video format.

  • Hey @Mying-Humtsoe

    I decided to put my answer in video format.

  • @avan thank you so much sir from the deepest of my heart, i have spent days trying to find answer to this problem and googling for solution but failed and i wanted to give up, you are a life saver 😥 😭

Log in to reply