Skip to content

Hello, world! #64

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
Expand Up @@ -4,7 +4,7 @@
<body>

<script>
alert( "I'm JavaScript!" );
alert( "მე ვარ JavaScript-ი!" );
</script>

</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<body>

<script>
alert( "I'm JavaScript!" );
alert( "მე ვარ JavaScript-ი!" );
</script>

</body>
Expand Down
7 changes: 3 additions & 4 deletions 1-js/02-first-steps/01-hello-world/1-hello-alert/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ importance: 5

---

# Show an alert
# გაფრთხილების ჩვენება

Create a page that shows a message "I'm JavaScript!".
შექმენით გვერდი, რომელიც აჩვენებს შეტყობინებას: „მე ვარ JavaScript-ი!“.

Do it in a sandbox, or on your hard drive, doesn't matter, just ensure that it works.
გააკეთეთ ეს sandbox-ში ან თქვენს მყარ დისკზე, არა აქვს მნიშვნელობა, უბრალოდ დარწმუნდით, რომ მუშაობს.

[demo src="solution"]

Original file line number Diff line number Diff line change
@@ -1 +1 @@
alert("I'm JavaScript!");
alert("მე ვარ JavaScript-ი!");
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
The HTML code:
HTML-კოდი:

[html src="index.html"]

For the file `alert.js` in the same folder:
იმავე საქაღალდეში არსებული `alert.js` ფაილისთვის:

[js src="alert.js"]

6 changes: 3 additions & 3 deletions 1-js/02-first-steps/01-hello-world/2-hello-alert-ext/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ importance: 5

---

# Show an alert with an external script
# გაფრთხილების ჩვენება გარე სკრიპტის გამოყენებით

Take the solution of the previous task <info:task/hello-alert>. Modify it by extracting the script content into an external file `alert.js`, residing in the same folder.
აიღეთ წინა დავალების (<info:task/hello-alert>) ამონახსნი და მოახდინეთ მასი ცვლილება. სკრიპტის შიგთავსი გაიტანეთ ცალკე `alert.js` ფაილში, რომელიც განთავსებულია იმავე საქაღალდეში.

Open the page, ensure that the alert works.
გახსენით გვერდი, დარწმუნდით, რომ გაფრთხილება მუშაობს.
84 changes: 42 additions & 42 deletions 1-js/02-first-steps/01-hello-world/article.md
Original file line number Diff line number Diff line change
@@ -1,87 +1,87 @@
# Hello, world!
# გამარჯობა, მსოფლიო!

This part of the tutorial is about core JavaScript, the language itself.
სახელმძღვანელოს ეს ნაწილი ეხება JavaScript-ს, უშუალოდ ენას.

But we need a working environment to run our scripts and, since this book is online, the browser is a good choice. We'll keep the amount of browser-specific commands (like `alert`) to a minimum so that you don't spend time on them if you plan to concentrate on another environment (like Node.js). We'll focus on JavaScript in the browser in the [next part](/ui) of the tutorial.
ამის მიუხედავად გვჭირდება სამუშაო გარემო, რათა გავუშვათ ჩვენი სკრიპტები და, რადგან ეს გახლავთ ონლაინ-წიგნი, ბრაუზერი ამისთვის მშვენიერი არჩევანია. ჩვენ მინიმუმამდე დავიყვანთ ბრაუზერისთვის სპეციფიკური ბრძანებების (როგორიცაა `alert`) რაოდენობას, რათა მათზე დრო არ დაკარგოთ [იმ შემთხვევაში], თუ გეგმავთ, კონცენტრირდეთ სხვა გარემოზე (როგორიცაა Node.js). ბრაუზერში JavaScript-ის გამოყენებაზე ყურადღებას გავამახვილებთ სახელმძღვანელოს [შემდეგ ნაწილში](/ui).

So first, let's see how we attach a script to a webpage. For server-side environments (like Node.js), you can execute the script with a command like `"node my.js"`.
მაშასადამე, თავდაპირველად ვნახოთ, როგორ ხდება ვებგვერდისათვის სკრიპტის მიბმა. სერვერის მხარის გარემოში (როგორიცაა Node.js) სკრიპტის გაშვება შეგიძლიათ შემდეგნაირი ბრძანებით: `„node my.js`.


## The "script" tag
## ტეგი „script

JavaScript programs can be inserted almost anywhere into an HTML document using the `<script>` tag.
JavaScript-პროგრამების განთავსება შესაძლებელია HTML-დოკუმენტის მასშტაბით, `<script>` ტეგის გამოყენებით.

For instance:
მაგალითად:

```html run height=100
<!DOCTYPE HTML>
<html>

<body>

<p>Before the script...</p>
<p>სკრიპტის წინ...</p>

*!*
<script>
alert( 'Hello, world!' );
alert( 'გამარჯობა, მსოფლიო!' );
</script>
*/!*

<p>...After the script.</p>
<p>...სკრიპტის შემდეგ.</p>

</body>

</html>
```

```online
You can run the example by clicking the "Play" button in the right-top corner of the box above.
ზემოთ მოცემული განყოფილების მარჯვენა ზედა კუთხეში არსებულ „Play“ ღილაკზე დაწკაპუნებით შეგიძლიათ მაგალითში მოცემული კოდი გაუშვათ.
```

The `<script>` tag contains JavaScript code which is automatically executed when the browser processes the tag.
`<script>` ტეგი შეიცავს JavaScript-კოდს, რომელიც, როგორც კი ბრაუზერის მიერ დამუშავდება, ავტომატურად ეშვება.


## Modern markup
## თანამედროვე მარკირება

The `<script>` tag has a few attributes that are rarely used nowadays but can still be found in old code:
`<script>` ტეგს გააჩნია რამდენიმე ატრიბუტი, რომლებიც დღესდღეობით იშვიათად გამოიყენება, მაგრამ მაინც გვხვდება ძველ კოდში:

The `type` attribute: <code>&lt;script <u>type</u>=...&gt;</code>
: The old HTML standard, HTML4, required a script to have a `type`. Usually it was `type="text/javascript"`. It's not required anymore. Also, the modern HTML standard totally changed the meaning of this attribute. Now, it can be used for JavaScript modules. But that's an advanced topic, we'll talk about modules in another part of the tutorial.
ატრიბუტი `type`: <code>&lt;script <u>type</u>=...&gt;</code>
: ძველი HTML-სტანდარტი, HTML4, სკრიპტისაგან მოითხოვდა `type`-ის ქონას. ჩვეულებრივ, იგი გვხვდებოდა შემდეგი მნიშვნელობით: `type="text/javascript"`. ამჟამად ეს აღარ არის აუცილებელი. ამასთან, თანამედროვე HTML-სტანდარტმა მთლიანად შეცვალა ამ ატრიბუტის დატვირთვა. ახლა იგი შეიძლება გამოყენებულ იქნეს JavaScript-მოდულებისათვის. მაგრამ ამაზე საუბარი ჯერჯერობით ნაადრევია, მოდულების შესახებ სახელმძღვანელოს სხვა ნაწილში ვისაუბრებთ.

The `language` attribute: <code>&lt;script <u>language</u>=...&gt;</code>
: This attribute was meant to show the language of the script. This attribute no longer makes sense because JavaScript is the default language. There is no need to use it.
ატრიბუტი `language`: <code>&lt;script <u>language</u>=...&gt;</code>
: ამ ატრიბუტის დანიშნულება სკრიპტის ენის აღნიშვნა იყო. თუმცა, რადგან [ამჟამად] JavaScript-ი ნაგულისხმევი ენაა, ამ ატრიბუტის გამოყენებას აზრი აღარ აქვს.

Comments before and after scripts.
: In really ancient books and guides, you may find comments inside `<script>` tags, like this:
კომენტარები სკრიპტის წინ და სკრიპტის შემდეგ.
: ძალიან ძველ წიგნებსა და სახელმძღვანელოებში `<script>` ტეგის შიგნით შეიძლება წააწყდეთ შემდეგი სახის კომენტარებს:

```html no-beautify
<script type="text/javascript"><!--
...
//--></script>
```

This trick isn't used in modern JavaScript. These comments hide JavaScript code from old browsers that didn't know how to process the `<script>` tag. Since browsers released in the last 15 years don't have this issue, this kind of comment can help you identify really old code.
აღნიშნული კომენტარის დანიშნულება ის გახლდათ, რომ იგი მალავდა JavaScript-კოდს ძველი ბრაუზერებისაგან, რომლებმაც არ იცოდნენ, როგორ დაემუშავებინათ `<script>` ტეგი. ეს ხრიკი თანამედროვე JavaScript-ში აღარ გამოიყენება. მას შემდეგ, რაც ბოლო 15 წლის განმავლობაში გამოშვებულ არც ერთ ბრაუზერს ეს პრობლემა აღარ აქვს, ერთადერთი, რაშიც მსგავსი კომენტარი შეიძლება დაგეხმაროთ, ჭეშმარიტად უძველესი კოდის იდენტიფიცირებაა.


## External scripts
## გარე სკრიპტები

If we have a lot of JavaScript code, we can put it into a separate file.
თუ დიდი მოცულობით JavaScript-კოდი გვაქვს, შეგვიძლია იგი ცალკეულ ფაილში განვათავსოთ.

Script files are attached to HTML with the `src` attribute:
სკრიპტის ფაილების HTML-ისთვის მიბმა ხორციელდება `src` ატრიბუტით:

```html
<script src="/path/to/script.js"></script>
```

Here, `/path/to/script.js` is an absolute path to the script from the site root. One can also provide a relative path from the current page. For instance, `src="script.js"` would mean a file `"script.js"` in the current folder.
აქ `/path/to/script.js` არის აბსოლუტური მისამართი საიტის ფესვიდან სკრიპტის ფაილამდე. ასევე შეიძლება მივუთითოთ ფარდობითი მისამართი მიმდინარე გვერდიდან. მაგალითად, `src="script.js"` [ან `src="./script.js"`] გულისხმობს, რომ `"script.js"` ფაილი განთავსებულია მიმდინარე საქაღალდეში.

We can give a full URL as well. For instance:
ასევე შეგვიძლია სრული URL-მისამართის მითითება. მაგალითად:

```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.js"></script>
```

To attach several scripts, use multiple tags:
რამდენიმე სკრიპტის მისაბმელად [ერთდროულად] ვიყენებთ მრავალ ტეგს:

```html
<script src="/js/script1.js"></script>
Expand All @@ -90,29 +90,29 @@ To attach several scripts, use multiple tags:
```

```smart
As a rule, only the simplest scripts are put into HTML. More complex ones reside in separate files.
როგორც წესი, HTML-ში თავსდება მხოლოდ უმარტივესი სკრიპტები, უფრო რთულები კი — ცალკეულ ფაილებში.

The benefit of a separate file is that the browser will download it and store it in its [cache](https://en.wikipedia.org/wiki/Web_cache).
ცალკეული ფაილის უპირატესობა ის გახლავთ, რომ ბრაუზერი მოახდენს მის ჩამოტვირთვას და [ქეშში](https://en.wikipedia.org/wiki/Web_cache) შენახვას.

Other pages that reference the same script will take it from the cache instead of downloading it, so the file is actually downloaded only once.
სხვა გვერდები, რომლებიც შეიცავენ იმავე სკრიპტს, ნაცვლად ჩამოტვირთვისა, ამოიღებენ მას ქეშიდან. ამრიგად, ფაილის ჩამოტვირთვა ფაქტობრივად მხოლოდ ერთხელ მოხდება.

That reduces traffic and makes pages faster.
ეს ამცირებს ტრაფიკს და გვერდებს უფრო სწრაფს ხდის.
```

````warn header="If `src` is set, the script content is ignored."
A single `<script>` tag can't have both the `src` attribute and code inside.
````warn header="თუ `src` ატრიბუტი განსაზღვრულია, `script` ტეგის შიგთავსი უგულებელყოფილი იქნება."
ერთსა და იმავე `<script>` ტეგში ერთდროულად `src` ატრიბუტისა და შიგთავსის ქონა არ შეიძლება.

This won't work:
ეს არ იმუშავებს:

```html
<script *!*src*/!*="file.js">
alert(1); // the content is ignored, because src is set
alert(1); // შიგთავსი უგულებელყოფილია, რადგან განსაზღვრულია src ატრიბუტი
</script>
```

We must choose either an external `<script src="…">` or a regular `<script>` with code.
უნდა გავაკეთოთ არჩევანი: ან გარე სკრიპტი `<script src="…">`, ან ჩვეულებრივი კოდი `<script>` ტეგის შიგნით.

The example above can be split into two scripts to work:
ზემოთ მოყვანილი მაგალითი შეიძლება დაიყოს ორ სკრიპტად, რათა (სრულფასოვნად) იმუშავოს:

```html
<script src="file.js"></script>
Expand All @@ -122,11 +122,11 @@ The example above can be split into two scripts to work:
```
````

## Summary
## შეჯამება

- We can use a `<script>` tag to add JavaScript code to a page.
- The `type` and `language` attributes are not required.
- A script in an external file can be inserted with `<script src="path/to/script.js"></script>`.
- გვერდისათვის JavaScript-კოდის დასამატებლად `<script>` ტეგი გამოიყენება.
- `type` და `language` ატრიბუტები არასავალდებულოა.
- გარე ფაილად არსებული სკრიპტის ჩასმა შემდეგნაირად არის შესაძლებელი: `<script src="path/to/script.js"></script>`.


There is much more to learn about browser scripts and their interaction with the webpage. But let's keep in mind that this part of the tutorial is devoted to the JavaScript language, so we shouldn't distract ourselves with browser-specific implementations of it. We'll be using the browser as a way to run JavaScript, which is very convenient for online reading, but only one of many.
ჯერ კიდევ ბევრი რამ გვაქვს განსახილველი ბრაუზერის სკრიპტებისა და ვებგვერდთან მათი ურთიერთქმედების შესახებ, მაგრამ, როგორც უკვე აღვნიშნეთ, სახელმძღვანელოს ეს ნაწილი მიეძღვნა პროგრამირების ენა JavaScript-ს, ასე რომ, ნუ გაამახვილებთ ყურადღებას ბრაუზერთან დაკავშირებულ დეტალებზე. ჩვენ გამოვიყენებთ ბრაუზერს, როგორც გზას JavaScript-ის გასაშვებად, რაც ონლაინ კითხვის კონტექსტში ძალიან მოსახერხებელია, თუმცა ეს არ გახლავთ ერთადერთი გზა.