In this HackerRank Day 6: Javascript Dates 10 days of javascript problem solution Given a date string, dateString, in the format MM/DD/YYYY, find and return the day name for that date. Each day name must be one of the following strings: Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, or Saturday. For example, the day name for the date 12/07/2016 is Wednesday.


HackerRank Day 6: JavaScript Dates problem solution


Problem solution in JavaScript programming.

// The days of the week are: "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
function getDayName(dateString) {
    let dayName;
    // Write your code here
    let day = new Date(dateString).getDay();
    if (day === 1){
        dayName = "Monday";
    }
    else if (day === 2){
        dayName = "Tuesday";
    }
    else if (day === 3){
        dayName = "Wednesday";
    }
    else if (day === 4){
        dayName = "Thursday";
    }
    else if (day === 5){
        dayName = "Friday";
    }
    else if (day === 6){
        dayName = "Saturday";
    }
    else {
        dayName = "Sunday";
    }
    
    return dayName;
}