curriculum/challenges/english/blocks/daily-coding-challenges-javascript/699c8e045ee7cb94ed2322dd.md
Today is the equinox, when the sun is directly above the equator and perfectly overhead at noon. Given a time, determine the shadow cast by a 4-foot vertical pole.
"HH:MM" 24-hour format (for example, "15:00" is 3pm).Rules:
"east", and sets at 6pm directly "west".Return:
"(length)ft (direction)". For example, "8ft west"."No shadow".For example, given "10:00", return "8ft west" because 10am is 2 hours from noon, so 2<sup>3</sup> = 8 feet, and the shadow points west because the sun is in the east at 10am.
getShadow("10:00") should return "8ft west".
assert.equal(getShadow("10:00"), "8ft west");
getShadow("15:00") should return "27ft east".
assert.equal(getShadow("15:00"), "27ft east");
getShadow("12:00") should return "No shadow".
assert.equal(getShadow("12:00"), "No shadow");
getShadow("17:30") should return "166.375ft east".
assert.equal(getShadow("17:30"), "166.375ft east");
getShadow("05:00") should return "No shadow".
assert.equal(getShadow("05:00"), "No shadow");
getShadow("06:00") should return "216ft west".
assert.equal(getShadow("06:00"), "216ft west");
getShadow("18:00") should return "No shadow".
assert.equal(getShadow("18:00"), "No shadow");
getShadow("07:30") should return "91.125ft west".
assert.equal(getShadow("07:30"), "91.125ft west");
getShadow("00:00") should return "No shadow".
assert.equal(getShadow("00:00"), "No shadow");
function getShadow(time) {
return time;
}
function getShadow(time) {
const [hourStr, minuteStr] = time.split(":");
const hours = Number(hourStr);
const minutes = Number(minuteStr);
const timeInHours = hours + minutes / 60;
if (timeInHours < 6 || timeInHours >= 18 || timeInHours === 12) {
return "No shadow";
}
const hoursFromNoon = Math.abs(12 - timeInHours);
const length = Math.pow(hoursFromNoon, 3);
const direction = timeInHours < 12 ? "west" : "east";
return `${length}ft ${direction}`;
}