Skip to content

Variables #15

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 13 commits into from
Nov 24, 2020
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.
I koden nedenfor forholder hver linje sig til linjen i opgavelisten.

```js run
let admin, name; // can declare two variables at once
let admin, name; // Du kan deklarere flere variable ad gangen

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
# Arbejde med variable

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. Opret to variable: `admin` og `name`.
2. Tildel værdien `"John"` til `name`.
3. Kopier værdien fra `name` til `admin`.
4. Vis værdien af `admin` med en `alert` (skal vise teksten "John").
16 changes: 11 additions & 5 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,27 @@
## The variable for our planet

That's simple:
Først, et variabelnavn til vores planet.

Den kunne simpelthen kaldes:

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

Note, we could use a shorter name `planet`, but it might be not obvious what planet it refers to. It's nice to be more verbose. At least until the variable isNotTooLong.
Læg mærke til, at du kunne have brugt et kortere navn som `planet`, men det ville ikke være tydeligt, at navnet refererede til vores egen planet. Det er en god ting at skrive navnene på variable ud. Så længe du ikke ender med altForLangeVariabelnavne.


## The name of the current visitor

Nummer to var navnet på den aktuelle besøgende:

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

Again, we could shorten that to `userName` if we know for sure that the user is current.
Igen, du kunne have skrevet det kortere med `userName` men hvordan kunne du så læse at det var den aktuelle bruger?

Moderne editorer autoudfylder lange variabelnavne, så det er nemmere are skrive koden, så lad vær med at spare på de lange navne. Et navn med omkring tre ord i er fint.

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.
Og, hvis din editor ikke har en ordentlig autoudfyldning, så [få en ny editor](/editors).

And if your editor does not have proper autocompletion, get [a new one](/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
# Giv en variabel det rigtige navn

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. Opret en variabel til navnet på vores planet. Hvordan vil du navgive sådan en variabel (på engelsk)?
2. Opret en variabel til at gemme navnet til den aktuelle besøgende på en side. Hvordan vil du navgive sådan en variabel (på engelsk)?
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.
Du skal generelt bruge uppercase til konstanter der er "hard-coded". Eller, sagt med andre ord, hvis du ved hvad værdien er når du skriver den og ikke når koden afvikles.

In this code, `birthday` is exactly like that. So we could use the upper case for it.
I denne kode er `birthday` præcist sådan en værdi, så her vil du bruge bar store bogstaver.

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.
Derimod vil `age` blive evalueret når koden afvikles. Idag vil du have én alder og næste år en anden. Den er en konstant i den forstand, at den ikke ændrer sig i det tidsrum koden afvikles. Men den er "lidt mindre konstant" end `birthday`. Da den er beregnet, vil du normalt skrive den i lowercase.
10 changes: 5 additions & 5 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 @@ -4,21 +4,21 @@ importance: 4

# Uppercase const?

Examine the following code:
Undersøg følgende kode:

```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).
Her har du en konstant `birthday` dato og `age` bliver beregnet fra `birthday` ved hjælp af noget kode (den kode er ikke vist for klarhedens skyld - og fordi det ikke er vigtigt i eksemplet).

Would it be right to use upper case for `birthday`? For `age`? Or even for both?
Vil det være rigtigt at bruge store bogstaver til `birthday`? Til `age`? Eller måske til begge?

```js
const BIRTHDAY = '18.04.1982'; // make uppercase?
const BIRTHDAY = '18.04.1982'; // lav til uppercase?

const AGE = someCode(BIRTHDAY); // make uppercase?
const AGE = someCode(BIRTHDAY); // lav til uppercase?
```

Loading