Skip to content

Basic operators, maths #85

New issue

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

Merged
merged 8 commits into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions 1-js/02-first-steps/08-operators/4-fix-prompt/solution.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The reason is that prompt returns user input as a string.
Պատճառը այն է որ մուտքագրված թվերը վերդարձվում են որպես տող։

So variables have values `"1"` and `"2"` respectively.
Այսպիսով փոփոխականները ունեն `"1"` և `"2"` արժեքները։

```js run
let a = "1"; // prompt("First number?", 1);
Expand All @@ -9,9 +9,9 @@ let b = "2"; // prompt("Second number?", 2);
alert(a + b); // 12
```

What we should do is to convert strings to numbers before `+`. For example, using `Number()` or prepending them with `+`.
Այն, ինչ մենք պետք է անենք, տողերը թվեր փոխարկելն է `+`-ից առաջ։ Օրինակ՝ կիրառելով `Number()` կամ դնելով դիմացից `+`։

For example, right before `prompt`:
Օրինակ՝ `prompt`-ից անմիջապես առաջ:

```js run
let a = +prompt("First number?", 1);
Expand All @@ -20,7 +20,7 @@ let b = +prompt("Second number?", 2);
alert(a + b); // 3
```

Or in the `alert`:
Կամ `alert`-ի մեջ:

```js run
let a = prompt("First number?", 1);
Expand All @@ -29,4 +29,4 @@ let b = prompt("Second number?", 2);
alert(+a + +b); // 3
```

Using both unary and binary `+` in the latest code. Looks funny, doesn't it?
Կիրառվել են և ունար և բինար `+`վերջին կոդւոմ։ Հիանալի տեսք ունի, այդպես չէ՞
8 changes: 4 additions & 4 deletions 1-js/02-first-steps/08-operators/4-fix-prompt/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ importance: 5

---

# Fix the addition
# Ուղղել գումարումը

Here's a code that asks the user for two numbers and shows their sum.
Գրված է կոդի հատված, որը օգտագործողից ստանում է երկու թվեր և ցուցադրում է դրանց գումարը։

It works incorrectly. The output in the example below is `12` (for default prompt values).
Սա աշխատում է սխալ։ Ելքային արդյունքը, պատկերված օրինակում `12`-է (լռելայն արժեքների դեպքում)։

Why? Fix it. The result should be `3`.
Ինչու՞ ուղղել դա։ Արդյունքը պետք է լինի `3`.

```js run
let a = prompt("First number?", 1);
Expand Down
Loading