Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

83 lines
1.3 KiB
Markdown

---
id: 69cfca90e8a0a6d4d6871c51
title: "Challenge 267: Parsec Converter"
challengeType: 28
dashedName: challenge-267
---
# --description--
In a distant galaxy, parsecs are used to measure both time and distance. Given an integer number of parsecs, return its equivalent in time or distance.
- If the given integer is odd, it represents time. If it's even, it represents distance.
Use these conversion rates:
| Parsecs | Time/Distance |
| - | - |
| 1 | 2 hours |
| 2 | 6 light years |
Return the converted value as an integer.
# --hints--
`convertParsecs(1)` should return `2`.
```js
assert.equal(convertParsecs(1), 2);
```
`convertParsecs(2)` should return `6`.
```js
assert.equal(convertParsecs(2), 6);
```
`convertParsecs(31)` should return `62`.
```js
assert.equal(convertParsecs(31), 62);
```
`convertParsecs(88)` should return `264`.
```js
assert.equal(convertParsecs(88), 264);
```
`convertParsecs(17)` should return `34`.
```js
assert.equal(convertParsecs(17), 34);
```
`convertParsecs(14)` should return `42`.
```js
assert.equal(convertParsecs(14), 42);
```
# --seed--
## --seed-contents--
```js
function convertParsecs(parsecs) {
return parsecs;
}
```
# --solutions--
```js
function convertParsecs(parsecs) {
if (parsecs % 2 !== 0) {
return parsecs * 2;
} else {
return parsecs * 3;
}
}
```