 Welcome to challenge 16! Use this thread for any and all questions relating to challenge 16.

Uhhh...

const festivalColours = color1 => [color1+150, color1+210]

4 Likes

This challenge is ridiculous…lol

``````const festivalColours = color1 => {
return [color1 + 210, color1 + 150];
}``````

Yeah, I noticed that too.

The order is reversed

Hope we going to get to a point where the challenge is challenging Solution

const festivalColours = color1 => [color1].map(c1 => [c1 + 150, c1 + 210])

I couldn’t get this to work until I changed my formula to not follow the one they link to. According to the page they link to, we need to subtract 360 degrees and take the absolute value:

• formula: H1 = |(H0 + 150 degrees) - 360 degrees|
• formula: H2 = |(H0 + 210 degrees) - 360 degrees|

Thus:

``````return [
Math.abs((color1 + 150) - 360),
Math.abs((color1 + 210) - 360)
].sort();
``````

But this apparently doesn’t produce the values they’re looking for so I had to make what I think is a pretty significant change to the formula:

``````  return [
color1 + 150,
color1 + 210
].sort();
``````

I don’t think this formula would work for large values of `color1`, such that the addition is greater than 360 degrees.

2 Likes

The absolute indicated in the formula is for degrees…
So: `(100˚ +150˚) - 360˚` give `-110`.
-110˚ in absolute is 250˚

Think about a circle where negative degree are always shown has positive…

Ohh, of course. Thanks!

That doesn’t fully solve the problem though - if color1 is 310, you’ll output 520 and 460

2 Likes

I don’t get the formula on that site, because if your value is less than 210 when adding 150 you don’t need to subtract 360.

Here’s my solution - each colour either adds 150, or finds the value on the other side of the circle based on the starting value of color1 (if it isn’t making sense, color1 + 150 - 360 is the same as color1-210)

const festivalColours = color1 => {
// code here!
splitColor1 = ((color1 + 150) > 360 ) ? color1-210 : color1+150;
splitColor2 = ((color1 + 210) > 360 ) ? color1-150 : color1+210;

return [splitColor1, splitColor2].sort();
}

2 Likes
My approach
``````const festivalColours = color1 => {
var x = (color1 + 150)-360; //split 1
var y = (color1 + 210)-360; //split 2
if (x<0){ x = x + 360}          // absolute in degrees
if (y<0){ y = y + 360}         // absolute in degrees
if (x>y){ x,y=y,x}                // minimum first
return [x,y];
}
``````
1 Like 1 Like

The formula that they point to in the link is not correct. It should be this:

``````100 + 150 = 250
100 + 210 = 310
``````

NOT this:

``````| 100 + 150 - 360 | = 110
| 100 + 210 - 360 | = 50
``````

IF color 2 and/or color3 are GREATER than 360, then subtract 360. Example:

``````color1 = 300
color2 = 300 + 150 - 360 = 90
color2 = 300 + 210 - 360 = 150
``````
1 Like

You forgot to subtract the values from 360 again:

``````[
360 - Math.abs((H0 + 150) - 360),
360 - Math.abs((H0 + 210) - 360),
]``````

Your `.sort()` will not work correctly for numbers 100 & 50 (for example) because javascript sorts alphabetically, and sees the ‘5’ in 50 being higher than the ‘1’ in 100, and therefore would sort 100 before 50.

``````const festivalColours = color1 => {
const normalize = color => (color <= 360 ? color : 360 - color);
return [normalize(color1 + 150), normalize(color1 + 210)];
};``````