Back to Freecodecamp

Challenge 176: Groundhog Day

curriculum/challenges/english/blocks/daily-coding-challenges-javascript/69738771fb5a7b8b24cca2a2.md

latest1.8 KB
Original Source

--description--

Today is Groundhog Day, in which a groundhog predicts the weather based on whether or not it sees its shadow.

Given a value representing the groundhog's appearance, return the correct prediction:

  • If the given value is the boolean true (the groundhog saw its shadow), return "Looks like we'll have six more weeks of winter.".
  • If the value is the boolean false (the groundhog did not see its shadow), return "It's going to be an early spring.".
  • If the value is anything else (the groundhog did not show up), return "No prediction this year.".

--hints--

groundhogDayPrediction(true) should return "Looks like we'll have six more weeks of winter.".

js
assert.equal(groundhogDayPrediction(true), "Looks like we'll have six more weeks of winter.");

groundhogDayPrediction(false) should return "It's going to be an early spring.".

js
assert.equal(groundhogDayPrediction(false), "It's going to be an early spring.");

groundhogDayPrediction(null) should return "No prediction this year.".

js
assert.equal(groundhogDayPrediction(null), "No prediction this year.");

groundhogDayPrediction(" ") should return "No prediction this year.".

js
assert.equal(groundhogDayPrediction(" "), "No prediction this year.");

groundhogDayPrediction("true") should return "No prediction this year.".

js
assert.equal(groundhogDayPrediction("true"), "No prediction this year.");

--seed--

--seed-contents--

js
function groundhogDayPrediction(appearance) {

  return appearance;
}

--solutions--

js
function groundhogDayPrediction(appearance) {
  if (appearance === true) return "Looks like we'll have six more weeks of winter.";
  if (appearance === false) return "It's going to be an early spring.";
  return "No prediction this year.";
}