Another 4 JavaScript tips for shorter code | by Abhinav VP | Nov, 2021 | Medium

PHOTO EMBED

Wed Dec 01 2021 17:02:56 GMT+0000 (UTC)

Saved by @MattMoniz #objects #javascript

function returnDayKeyValue(val) {
    const returnDayObject = {
        1: "It's monday",
        2: "It's tuesday",
        3: "It's wednesday",
        4: "It's thursday",
        5: "It's friday",
        6: "It's saturday",
        7: "It's sunday",
    }
    if(!returnDayObject[val]){
     return "Enter a value between 1 - 7";
    }
    return returnDayObject[val]
}
cosnt day = 3;
console.log(returnDayKeyValue(day)); //It's wednesday
content_copyCOPY

https://medium.com/@abhinav_vp/another-4-javascript-tips-for-shorter-code-64791c1111b4