Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

425
Views
How to solve Error with switch Function - JavaScript

I am trying to create a function that gives me the month depending on the console.log info.

    function daysInMonth(month) {
  switch (month) {
    case '1': case '3': case '5': case '7': case '8': case '10': case '12':
      return '31';
    case '2':
      return '28';
    case '4': case '6': case '9': case '11':
      return '30';
    default:
      return 'You have to put a month from 1 to 12';
  }
}
var result = daysInMonth('1');
var result = daysInMonth('6');
var result = daysInMonth('2');

I am given some errors:

Log 31 30 28 function daysInMonth (month) function daysInMonth should be declared should return 31 when month is one of the following values: 1,3,5,7,8,10,12 function should return 31 when month is one of the following 1, 3, 5, 7, 8, 10, 12 : expected 'You have to put a month from 1 to 12' to equal 31 Completed in 2ms should return 30 when month is one of the following values: 4, 6, 9, 11 function should return 30 when month is one of the following 4, 6, 9, 11 : expected 'You have to put a month from 1 to 12' to equal 30 should return 28 when month is 2 function should return 28 when month is 2 : expected 'You have to put a month from 1 to 12' to equal 28

This is what I was asked to do:

Implement the logic of the function named daysInMonth. The function receives one argument month, which is an integer (whole number) in the range from 1 to 12.

It should return a number of days depending on the month of the year, as per the given table:

+-----------------+------------+ | month | days | +-----------------+------------+ | 1,3,5,7,8,10,12 | 31 | +-----------------+------------+ | 4,6,9,11 | 30 | +-----------------+------------+ | 2 | 28 | +-----------------+------------+ Important: You must use the keyword return to return the value from the function. Tests can only check the output value that your function returns. Any console.log output will be ignored.

I made the changes with the return, as I was assuming I had to console.log everything. Still, errors occur. Can you please help?

Thanks!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I was defining a string when I was supposed to define cases as integers. Re-read the request and got to that conclusion.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!