2018-09-30 23:01:58 +01:00
|
|
|
---
|
|
|
|
id: cf1111c1c11feddfaeb3bdef
|
|
|
|
title: Add Two Numbers with JavaScript
|
|
|
|
challengeType: 1
|
2019-02-14 12:24:02 -05:00
|
|
|
videoUrl: 'https://scrimba.com/c/cM2KBAG'
|
2019-07-31 11:32:23 -07:00
|
|
|
forumTopicId: 16650
|
2021-01-13 03:31:00 +01:00
|
|
|
dashedName: add-two-numbers-with-javascript
|
2018-09-30 23:01:58 +01:00
|
|
|
---
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --description--
|
|
|
|
|
|
|
|
`Number` is a data type in JavaScript which represents numeric data.
|
|
|
|
|
2018-09-30 23:01:58 +01:00
|
|
|
Now let's try to add two numbers using JavaScript.
|
2020-11-27 19:02:05 +01:00
|
|
|
|
|
|
|
JavaScript uses the `+` symbol as an addition operator when placed between two numbers.
|
|
|
|
|
|
|
|
**Example:**
|
2019-05-17 06:20:30 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
myVar = 5 + 10; // assigned 15
|
|
|
|
```
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --instructions--
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
Change the `0` so that sum will equal `20`.
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --hints--
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
`sum` should equal `20`.
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
```js
|
|
|
|
assert(sum === 20);
|
2018-09-30 23:01:58 +01:00
|
|
|
```
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
You should use the `+` operator.
|
2018-09-30 23:01:58 +01:00
|
|
|
|
|
|
|
```js
|
2020-11-27 19:02:05 +01:00
|
|
|
assert(/\+/.test(code));
|
2018-09-30 23:01:58 +01:00
|
|
|
```
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --seed--
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
## --after-user-code--
|
2018-09-30 23:01:58 +01:00
|
|
|
|
|
|
|
```js
|
2018-10-20 21:02:47 +03:00
|
|
|
(function(z){return 'sum = '+z;})(sum);
|
2018-09-30 23:01:58 +01:00
|
|
|
```
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
## --seed-contents--
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
```js
|
|
|
|
var sum = 10 + 0;
|
|
|
|
```
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --solutions--
|
2018-09-30 23:01:58 +01:00
|
|
|
|
|
|
|
```js
|
|
|
|
var sum = 10 + 10;
|
|
|
|
```
|