Operators by Gabitzzz · Pull Request #147 · javascript-tutorial/ro.javascript.info
@@ -1,32 +1,31 @@
The reason is that prompt returns user input as a string.
So variables have values `"1"` and `"2"` respectively.
Motivul este că prompt returnează inputul utilizatorului ca și un șir.
Astfel variable au valorile `"1"` și `"2"` respectiv.
```js run let a = "1"; // prompt("First number?", 1); let b = "2"; // prompt("Second number?", 2); let a = "1"; // prompt("Primul număr?", 1); let b = "2"; // prompt("Al doilea număr?", 2);
alert(a + b); // 12 ```
What we should do is to convert strings to numbers before `+`. For example, using `Number()` or prepending them with `+`. Ce ar trebui noi să facem este să convertim șirurile în numere înainte de `+`. De exemplu, folosind `Number()` sau să le adăugam `+` în față.
For example, right before `prompt`: De exemplu, chiar înainte de `prompt`:
```js run let a = +prompt("First number?", 1); let b = +prompt("Second number?", 2); let a = +prompt("Primul număr?", 1); let b = +prompt("Al doilea număr?", 2);
alert(a + b); // 3 ```
Or in the `alert`: Sau în `alert`:
```js run let a = prompt("First number?", 1); let b = prompt("Second number?", 2); let a = prompt("Primul număr?", 1); let b = prompt("Al doilea număr?", 2);
alert(+a + +b); // 3 ```
Using both unary and binary `+` in the latest code. Looks funny, doesn't it? Folosind atât `+` unar cât și binar în cel mai recent cod. Arată amuzant, nu-i așa?
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
După instrucțiuni, trebuie să păstrăm liniile "așa cum sunt". Acest lucru reduce conflictele de merge.
Sugestie: adaugă o linie goală între linia 1 și 2.
```js run let a = "1"; // prompt("First number?", 1); let b = "2"; // prompt("Second number?", 2); let a = "1"; // prompt("Primul număr?", 1); let b = "2"; // prompt("Al doilea număr?", 2);
alert(a + b); // 12 ```
What we should do is to convert strings to numbers before `+`. For example, using `Number()` or prepending them with `+`. Ce ar trebui noi să facem este să convertim șirurile în numere înainte de `+`. De exemplu, folosind `Number()` sau să le adăugam `+` în față.
For example, right before `prompt`: De exemplu, chiar înainte de `prompt`:
```js run let a = +prompt("First number?", 1); let b = +prompt("Second number?", 2); let a = +prompt("Primul număr?", 1); let b = +prompt("Al doilea număr?", 2);
alert(a + b); // 3 ```
Or in the `alert`: Sau în `alert`:
```js run let a = prompt("First number?", 1); let b = prompt("Second number?", 2); let a = prompt("Primul număr?", 1); let b = prompt("Al doilea număr?", 2);
alert(+a + +b); // 3 ```
Using both unary and binary `+` in the latest code. Looks funny, doesn't it? Folosind atât `+` unar cât și binar în cel mai recent cod. Arată amuzant, nu-i așa?