---
id: 6a1d9f98e819ed70a0e994e2
title: "Challenge 336: Horoscope Match"
challengeType: 28
dashedName: challenge-336
---

# --description--

Given two star sign strings, return their compatibility percentage.

The signs are arranged in a wheel of 12 positions in this order: `"Aries"`, `"Taurus"`, `"Gemini"`, `"Cancer"`, `"Leo"`, `"Virgo"`, `"Libra"`, `"Scorpio"`, `"Sagittarius"`, `"Capricorn"`, `"Aquarius"`, `"Pisces"`, wrapping back to `"Aries"` after `"Pisces"`. Find the shortest distance between the two signs and return the compatibility:

| Distance | Compatibility |
|----------|---------------|
| 0 | `"100%"` |
| 1 | `"40%"` |
| 2 | `"80%"` |
| 3 | `"30%"` |
| 4 | `"90%"` |
| 5 | `"20%"` |
| 6 | `"50%"` |

# --hints--

`horoscopeMatch("Libra", "Sagittarius")` should return `"80%"`.

```js
assert.equal(horoscopeMatch("Libra", "Sagittarius"), "80%");
```

`horoscopeMatch("Gemini", "Scorpio")` should return `"20%"`.

```js
assert.equal(horoscopeMatch("Gemini", "Scorpio"), "20%");
```

`horoscopeMatch("Pisces", "Aries")` should return `"40%"`.

```js
assert.equal(horoscopeMatch("Pisces", "Aries"), "40%");
```

`horoscopeMatch("Capricorn", "Cancer")` should return `"50%"`.

```js
assert.equal(horoscopeMatch("Capricorn", "Cancer"), "50%");
```

`horoscopeMatch("Aquarius", "Aquarius")` should return `"100%"`.

```js
assert.equal(horoscopeMatch("Aquarius", "Aquarius"), "100%");
```

`horoscopeMatch("Virgo", "Taurus")` should return `"90%"`.

```js
assert.equal(horoscopeMatch("Virgo", "Taurus"), "90%");
```

`horoscopeMatch("Leo", "Scorpio")` should return `"30%"`.

```js
assert.equal(horoscopeMatch("Leo", "Scorpio"), "30%");
```

# --seed--

## --seed-contents--

```js
function horoscopeMatch(sign1, sign2) {

  return sign1;
}
```

# --solutions--

```js
function horoscopeMatch(sign1, sign2) {
  const signs = ["Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces"];
  
  const a = signs.indexOf(sign1) + 1;
  const b = signs.indexOf(sign2) + 1;
  const diff = Math.abs(a - b);
  const distance = Math.min(diff, 12 - diff);

  const compatibility = { 0: "100%", 1: "40%", 2: "80%", 3: "30%", 4: "90%", 5: "20%", 6: "50%" };
  return compatibility[distance];
}
```
