본문 바로가기
알고리즘/Codewars

[Codewars] Return the day (8 kyu) / JavaScript

by fluss 2023. 4. 10.

https://www.codewars.com/kata/59dd3ccdded72fc78b000b25

 

Codewars - Achieve mastery through coding practice and developer mentorship

A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!

www.codewars.com

 

DESCRIPTION:

Complete the function which returns the weekday according to the input number:

  • 1 returns "Sunday"
  • 2 returns "Monday"
  • 3 returns "Tuesday"
  • 4 returns "Wednesday"
  • 5 returns "Thursday"
  • 6 returns "Friday"
  • 7 returns "Saturday"
  • Otherwise returns "Wrong, please enter a number between 1 and 7"

 

코드

function whatday(num) { 

  // put your code here

  const weekday = {
    1 : "Sunday",
    2 : "Monday",
    3 : "Tuesday",
    4 : "Wednesday",
    5 : "Thursday",
    6 : "Friday",
    7 : "Saturday"
  }
  return weekday[num] || 'Wrong, please enter a number between 1 and 7';

}

댓글