Skip to content
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
10 changes: 5 additions & 5 deletions 1-js/02-first-steps/08-operators/1-increment-order/solution.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

The answer is:
Odgovor je:

- `a = 2`
- `b = 2`
Expand All @@ -9,10 +9,10 @@ The answer is:
```js run no-beautify
let a = 1, b = 1;

alert( ++a ); // 2, prefix form returns the new value
alert( b++ ); // 1, postfix form returns the old value
alert( ++a ); // 2, prefix forma vraća novu vrijednost
alert( b++ ); // 1, postfix forma vraća staru vrijednost

alert( a ); // 2, incremented once
alert( b ); // 2, incremented once
alert( a ); // 2, povećana jednom
alert( b ); // 2, povećana jednom
```

6 changes: 3 additions & 3 deletions 1-js/02-first-steps/08-operators/1-increment-order/task.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
importance: 5
važnost: 5

---

# The postfix and prefix forms
# Postfix i prefix forme

What are the final values of all variables `a`, `b`, `c` and `d` after the code below?
Koje su finalne vrijednost varijabli `a`, `b`, `c` i `d` poslije koda ispod?

```js
let a = 1, b = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
The answer is:
Odgovor je:

- `a = 4` (multiplied by 2)
- `x = 5` (calculated as 1 + 4)
- `a = 4` (pomnoženo sa 2)
- `x = 5` (izračunato kao 1 + 4)

6 changes: 3 additions & 3 deletions 1-js/02-first-steps/08-operators/2-assignment-result/task.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
importance: 3
važnost: 3

---

# Assignment result
# Rezultat dodjele

What are the values of `a` and `x` after the code below?
Koje su vrijednosti varijabli `a` i `x` poslije koda ispod?

```js
let a = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ undefined + 1 = NaN // (6)
" \t \n" - 2 = -2 // (7)
```

1. The addition with a string `"" + 1` converts `1` to a string: `"" + 1 = "1"`, and then we have `"1" + 0`, the same rule is applied.
2. The subtraction `-` (like most math operations) only works with numbers, it converts an empty string `""` to `0`.
3. The addition with a string appends the number `5` to the string.
4. The subtraction always converts to numbers, so it makes `" -9 "` a number `-9` (ignoring spaces around it).
5. `null` becomes `0` after the numeric conversion.
6. `undefined` becomes `NaN` after the numeric conversion.
7. Space characters, are trimmed off string start and end when a string is converted to a number. Here the whole string consists of space characters, such as `\t`, `\n` and a "regular" space between them. So, similarly to an empty string, it becomes `0`.
1. Sabiranje sa string-om `"" + 1` pretvara `1` u string: `"" + 1 = "1"`, onda imamo `"1" + 0`, isto pravilo je primijenjeno.
2. Oduzimanje `-` (kao većina matematičkih operacija) radi samo sa brojevima, uvijek pretvara prazan string `""` u `0`.
3. Sabiranje sa string-om nadodaje broj `5` na string.
4. Oduzimanje uvijek pretvara u brojeve, tako da pretvara `" -9 "` u broj `-9` (ignoriše razmake okolo).
5. `null` postaje `0` nakon numeričke konverzije.
6. `undefined` postaje `NaN` nakon numeričke konverzije.
7. Razmaci su sklonjeni sa početka i kraja string-a kada ga pretvaramo u broj. Ovdje se čitav string sastoji od razmaka, kao što su `\t`, `\n` i "obični" razmak između njih. Tako da, slično praznom string-u, postaje `0`.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
importance: 5
važnost: 5

---

# Type conversions
# Konverzije tipova podataka

What are results of these expressions?
Koji su rezultati ovih izraza?

```js no-beautify
"" + 1 + 0
Expand All @@ -24,4 +24,4 @@ undefined + 1
" \t \n" - 2
```

Think well, write down and then compare with the answer.
Razmisli dobro, napiši i poredi sa odgovorom.
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.
Razlog je zato što prompt vraća unos korisnika kao string.

So variables have values `"1"` and `"2"` respectively.
Tako da varijable imaju vrijednosti `"1"` i `"2"` respketivno.

```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 to is to convert strings to numbers before `+`. For example, using `Number()` or prepending them with `+`.
Ono šta mi trebamo uraditi jeste pretvoriti string-ove u brojeve prije `+`. Na primjer, koristeći `Number()` ili dodavajući `+` ispred njih.

For example, right before `prompt`:
Na primjer, prije `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`:
Ili u `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?
Koristimo i unary i binarne `+` u zadnjem kodu. Izgleda smiješno, zar ne?
10 changes: 5 additions & 5 deletions 1-js/02-first-steps/08-operators/4-fix-prompt/task.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
importance: 5
važnost: 5

---

# Fix the addition
# Popravi sabiranje

Here's a code that asks the user for two numbers and shows their sum.
Ovdje imamo kod koji pita korisnika za dva broja i prikazuje njihov zbir.

It works incorrectly. The output in the example below is `12` (for default prompt values).
Ne radi ispravno. Izlaz u primjeru ispod je `12` (za uobičajene prompt vrijednosti).

Why? Fix it. The result should be `3`.
Zašto? Popravi. Rezultat treba biti `3`.

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