1.8 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 68c1a929005bf54d342aa8d2 | Challenge 55: Space Week Day 1: Stellar Classification | 28 | challenge-55 |
--description--
October 4th marks the beginning of World Space Week. The next seven days will bring you astronomy-themed coding challenges.
For today's challenge, you are given the surface temperature of a star in Kelvin (K) and need to determine its stellar classification based on the following ranges:
-
"O": 30,000 K or higher -
"B": 10,000 K - 29,999 K -
"A": 7,500 K - 9,999 K -
"F": 6,000 K - 7,499 K -
"G": 5,200 K - 5,999 K -
"K": 3,700 K - 5,199 K -
"M": 0 K - 3,699 K -
Return the classification of the given star.
--hints--
classification(5778) should return "G".
assert.equal(classification(5778), "G");
classification(2400) should return "M".
assert.equal(classification(2400), "M");
classification(9999) should return "A".
assert.equal(classification(9999), "A");
classification(3700) should return "K".
assert.equal(classification(3700), "K");
classification(3699) should return "M".
assert.equal(classification(3699), "M");
classification(210000) should return "O".
assert.equal(classification(210000), "O");
classification(6000) should return "F".
assert.equal(classification(6000), "F");
classification(11432) should return "B".
assert.equal(classification(11432), "B");
--seed--
--seed-contents--
function classification(temp) {
return temp;
}
--solutions--
function classification(temp) {
if (temp >= 30000) return "O";
if (temp >= 10000) return "B";
if (temp >= 7500) return "A";
if (temp >= 6000) return "F";
if (temp >= 5200) return "G";
if (temp >= 3700) return "K";
return "M";
}