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
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter