2021-02-06 04:42:36 +00:00
|
|
|
---
|
|
|
|
id: 56533eb9ac21ba0edf2244ac
|
2021-03-10 08:16:44 -07:00
|
|
|
title: Incrementa un número con JavaScript
|
2021-02-06 04:42:36 +00:00
|
|
|
challengeType: 1
|
|
|
|
videoUrl: 'https://scrimba.com/c/ca8GLT9'
|
|
|
|
forumTopicId: 18201
|
|
|
|
dashedName: increment-a-number-with-javascript
|
|
|
|
---
|
|
|
|
|
|
|
|
# --description--
|
|
|
|
|
2021-03-10 08:16:44 -07:00
|
|
|
Puedes fácilmente <dfn>incrementar</dfn> o sumar uno a una variable con el operador `++`.
|
2021-02-06 04:42:36 +00:00
|
|
|
|
2021-03-31 22:38:36 +09:00
|
|
|
```js
|
|
|
|
i++;
|
|
|
|
```
|
2021-02-06 04:42:36 +00:00
|
|
|
|
2021-03-10 08:16:44 -07:00
|
|
|
es equivalente a
|
2021-02-06 04:42:36 +00:00
|
|
|
|
2021-03-31 22:38:36 +09:00
|
|
|
```js
|
|
|
|
i = i + 1;
|
|
|
|
```
|
2021-02-06 04:42:36 +00:00
|
|
|
|
2021-03-10 08:16:44 -07:00
|
|
|
**Nota:** Toda la línea se convierte en `i++;`, eliminando la necesidad del signo de igualdad.
|
2021-02-06 04:42:36 +00:00
|
|
|
|
|
|
|
# --instructions--
|
|
|
|
|
2021-03-10 08:16:44 -07:00
|
|
|
Cambia el código para usar el operador `++` en `myVar`.
|
2021-02-06 04:42:36 +00:00
|
|
|
|
|
|
|
# --hints--
|
|
|
|
|
2021-03-10 08:16:44 -07:00
|
|
|
`myVar` debe ser igual a `88`.
|
2021-02-06 04:42:36 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert(myVar === 88);
|
|
|
|
```
|
|
|
|
|
2021-03-10 08:16:44 -07:00
|
|
|
No debes utilizar el operador de asignación.
|
2021-02-06 04:42:36 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert(
|
2021-10-27 15:10:57 +00:00
|
|
|
/let\s*myVar\s*=\s*87;\s*\/*.*\s*([+]{2}\s*myVar|myVar\s*[+]{2});/.test(code)
|
2021-02-06 04:42:36 +00:00
|
|
|
);
|
|
|
|
```
|
|
|
|
|
2021-03-10 08:16:44 -07:00
|
|
|
Debes usar el operador `++`.
|
2021-02-06 04:42:36 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert(/[+]{2}\s*myVar|myVar\s*[+]{2}/.test(code));
|
|
|
|
```
|
|
|
|
|
2021-03-10 08:16:44 -07:00
|
|
|
No debes cambiar el código por encima del comentario especificado.
|
2021-02-06 04:42:36 +00:00
|
|
|
|
|
|
|
```js
|
2021-10-27 15:10:57 +00:00
|
|
|
assert(/let myVar = 87;/.test(code));
|
2021-02-06 04:42:36 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
# --seed--
|
|
|
|
|
|
|
|
## --after-user-code--
|
|
|
|
|
|
|
|
```js
|
|
|
|
(function(z){return 'myVar = ' + z;})(myVar);
|
|
|
|
```
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
```js
|
2021-10-27 15:10:57 +00:00
|
|
|
let myVar = 87;
|
2021-02-06 04:42:36 +00:00
|
|
|
|
|
|
|
// Only change code below this line
|
|
|
|
myVar = myVar + 1;
|
|
|
|
```
|
|
|
|
|
|
|
|
# --solutions--
|
|
|
|
|
|
|
|
```js
|
2021-10-27 15:10:57 +00:00
|
|
|
let myVar = 87;
|
2021-02-06 04:42:36 +00:00
|
|
|
myVar++;
|
|
|
|
```
|