Skip to content

Variables #20

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 2 commits into from
Sep 25, 2021
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
In the code below, each line corresponds to the item in the task list.
Alla olevassa koodissa kukin rivi vastaa tehtävänannon kohtia.

```js run
let admin, name; // can declare two variables at once
let admin, name; // kaksi muuttujaa voi esitellä kerralla

name = "John";

Expand Down
10 changes: 5 additions & 5 deletions 1-js/02-first-steps/04-variables/1-hello-variables/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ importance: 2

---

# Working with variables
# Muuttujien käsittely

1. Declare two variables: `admin` and `name`.
2. Assign the value `"John"` to `name`.
3. Copy the value from `name` to `admin`.
4. Show the value of `admin` using `alert` (must output "John").
1. Esittele kaksi muuttujaa: `admin` ja `name`.
2. Anna arvo `"John"` muuttujalle `name`.
3. Kopioi muuttujan `name` arvo muuttujaan `admin`.
4. Näytä muuttujan `admin` arvo käyttämällä `alert` komentoa (tuloksen on oltava "John").
14 changes: 7 additions & 7 deletions 1-js/02-first-steps/04-variables/2-declare-variables/solution.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
## The variable for our planet
## Muuttuja planeettamme nimelle

That's simple:
Tämä on yksinkertaista:

```js
let ourPlanetName = "Earth";
```

Note, we could use a shorter name `planet`, but it might not be obvious what planet it refers to. It's nice to be more verbose. At least until the variable isNotTooLong.
Huomaa, että voisimme käyttää myös lyhyempää nimeä `planet`, mutta silloin ei olisi selvää, mihin planeettaan viitataan. On hyvä olla kuvaava. Ainakin kunnes muuttujan nimiOnLiianPitka.

## The name of the current visitor
## Nykyisen vierailijan nimi

```js
let currentUserName = "John";
```

Again, we could shorten that to `userName` if we know for sure that the user is current.
Voisimme taas lyhentää tämän muotoon `userName`, jos tiedämme varmasti, että kyseessä on tämänhetkinen käyttäjä.

Modern editors and autocomplete make long variable names easy to write. Don't save on them. A name with 3 words in it is fine.
Nykyaikaiset editorit ja automaattinen tekstintäyttö tekevät pitkistä muuttujien nimistä helppoja kirjoittaa. Älä säästele niistä. Kolmesanainen nimi käy hyvin.

And if your editor does not have proper autocompletion, get [a new one](/code-editors).
Ja jos editorisi ei tuoe automaattista tekstintäyttöä, hanki [uusi](/code-editors).
6 changes: 3 additions & 3 deletions 1-js/02-first-steps/04-variables/2-declare-variables/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ importance: 3

---

# Giving the right name
# Oikea nimeämistapa

1. Create a variable with the name of our planet. How would you name such a variable?
2. Create a variable to store the name of a current visitor to a website. How would you name that variable?
1. Luo muuttuja, joka saa arvokseen planeettamme nimen. Miten nimeäisit tällaisen muuttujan?
2. Luo muuttuja, joka saa arvokseen nettisivun tämänhetkisen käyttänän nimen. Miten nimeäisit tämän muuttujan?
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
We generally use upper case for constants that are "hard-coded". Or, in other words, when the value is known prior to execution and directly written into the code.
Yleisesti käytämme vakiomuuttujissa isoja kirjaimia, jos ne on "kovakoodattu". Eli, toisin sanoen, kun niiden arvo tunnetaan ennen koodin suorittamista ja kirjoitetaan suoraan koodiin.

In this code, `birthday` is exactly like that. So we could use the upper case for it.
Tässä koodissa, `birthday` on juuri tuollainen. Käyttäisimme siis sen yhteydessä isoja kirjaimia.

In contrast, `age` is evaluated in run-time. Today we have one age, a year after we'll have another one. It is constant in a sense that it does not change through the code execution. But it is a bit "less of a constant" than `birthday`: it is calculated, so we should keep the lower case for it.
Tätä vastoin `age` määritellään koodin suorittamisen aikana. Tänään meillä on yksi ikä, vuoden päästä toinen. Muuttuja on vakio siinä mielessä, että se ei muutu koodin suorituksen aikana. Se on kuitenkin vähän "vähemmän vakio" kuin `birthday`: se lasketaan, joten käytämme siinä pieniä kirjaimia.
12 changes: 6 additions & 6 deletions 1-js/02-first-steps/04-variables/3-uppercast-constant/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ importance: 4

---

# Uppercase const?
# Isokirjaiminen const?

Examine the following code:
Tutki seuraavaa koodia:

```js
const birthday = '18.04.1982';

const age = someCode(birthday);
```

Here we have a constant `birthday` date and the `age` is calculated from `birthday` with the help of some code (it is not provided for shortness, and because details don't matter here).
Meillä on vakiomuuttuja `birthday` päivämäärä ja `age` lasketaan muuttujan `birthday` avulla jonkin koodin avulla (sitä ei ole tässä näkyvillä, koska yksityiskohdilla ei ole tässä kohtaa merkitystä).

Would it be right to use upper case for `birthday`? For `age`? Or even for both?
Käyttäisitkö isoja kirjaimia muuttujalle `birthday`? Entä `age`? Tai jopa molemmissa?

```js
const BIRTHDAY = '18.04.1982'; // make uppercase?
const BIRTHDAY = '18.04.1982'; // käytä isoja kirjaimia?

const AGE = someCode(BIRTHDAY); // make uppercase?
const AGE = someCode(BIRTHDAY); // käytä isoja kirjaimia?
```

Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy