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
62 lines
1.1 KiB
Markdown
62 lines
1.1 KiB
Markdown
---
|
|
id: 6619240f46cec8e04d77e03a
|
|
title: Basic Functions Exercise A
|
|
challengeType: 1
|
|
dashedName: top-basic-functions-exercise-a
|
|
---
|
|
|
|
# --description--
|
|
|
|
Create a function that takes in an integer. This function should return the given `integer + 7` if the integer is less than `10`. If the integer is greater than or equal to `10`, it should return the given `integer - 3`.
|
|
|
|
The name of the function should be `addOrSubtract`.
|
|
|
|
# --hints--
|
|
|
|
You should have a function called `addOrSubtract`.
|
|
|
|
```js
|
|
assert.isFunction(addOrSubtract);
|
|
```
|
|
|
|
Your function should take in an integer as an argument.
|
|
|
|
```js
|
|
assert.match(addOrSubtract.toString(), /\s*addOrSubtract\(\s*\w+\s*\)/);
|
|
```
|
|
|
|
You should return the given integer + 7 if the integer is less than 10.
|
|
|
|
```js
|
|
assert.strictEqual(addOrSubtract(5), 12);
|
|
```
|
|
|
|
You should return the given integer - 3 if the integer is greater than or equal to 10.
|
|
|
|
```js
|
|
assert.strictEqual(addOrSubtract(10), 7);
|
|
```
|
|
|
|
|
|
|
|
|
|
# --seed--
|
|
|
|
## --seed-contents--
|
|
|
|
```js
|
|
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```js
|
|
function addOrSubtract(num) {
|
|
if (num < 10) {
|
|
return num + 7;
|
|
} else {
|
|
return num - 3;
|
|
}
|
|
}
|
|
```
|