| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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? | ||
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityDupă 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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.