Javascript: различия между версиями
Перейти к навигации
Перейти к поиску
(Новая страница: «== Hello World == * Hello#Javascript - PhpStorm») |
|||
(не показаны 4 промежуточные версии этого же участника) | |||
Строка 1: | Строка 1: | ||
+ | {{TOCRight}} | ||
+ | |||
== Hello World == | == Hello World == | ||
− | * [[Hello | + | * [[Hello - Javascript]] |
+ | |||
+ | == Объявление переменных == | ||
+ | * [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var JavaScript reference - Statements and declarations - var] | ||
+ | |||
+ | <syntaxhighlight lang="javascript" line> | ||
+ | var x = 1; | ||
+ | var y = 3.5; | ||
+ | var ready = true; | ||
+ | var name = 'Oleg'; | ||
+ | var age = [3, 15, 21, 35, 7]; | ||
+ | var car = {'brand': 'Volvo', 'model': 'XC90', age: 3.5, price: 'priceless'}; | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | == Ввод и вывод == | ||
+ | <syntaxhighlight lang="c#" line> | ||
+ | var age = prompt("Please, enter your age:"); | ||
+ | alert("Your age = " + age); | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | == Условный оператор == | ||
+ | <syntaxhighlight lang="c#" line> | ||
+ | var age = prompt("Please, enter your age:"); | ||
+ | if (age > 65) | ||
+ | { | ||
+ | alert("Here is your pension."); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | alert("Good morning people!"); | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | == Циклы == | ||
+ | <syntaxhighlight lang="c#" line> | ||
+ | alert("while loop\n"); | ||
+ | int i = 1; | ||
+ | while (i < 11) | ||
+ | { | ||
+ | alert(i); | ||
+ | i++; | ||
+ | } | ||
+ | |||
+ | alert("do while loop\n"); | ||
+ | i = 1; | ||
+ | do | ||
+ | { | ||
+ | alert(i); | ||
+ | i++; | ||
+ | } while (i < 11); | ||
+ | |||
+ | alert("for loop\n"); | ||
+ | for (int j = 1; j < 11; j++) | ||
+ | { | ||
+ | alert(j); | ||
+ | } | ||
+ | </syntaxhighlight> |
Текущая версия на 11:27, 27 ноября 2020
Hello World
Объявление переменных
1 var x = 1;
2 var y = 3.5;
3 var ready = true;
4 var name = 'Oleg';
5 var age = [3, 15, 21, 35, 7];
6 var car = {'brand': 'Volvo', 'model': 'XC90', age: 3.5, price: 'priceless'};
Ввод и вывод
1 var age = prompt("Please, enter your age:");
2 alert("Your age = " + age);
Условный оператор
1 var age = prompt("Please, enter your age:");
2 if (age > 65)
3 {
4 alert("Here is your pension.");
5 }
6 else
7 {
8 alert("Good morning people!");
9 }
Циклы
1 alert("while loop\n");
2 int i = 1;
3 while (i < 11)
4 {
5 alert(i);
6 i++;
7 }
8
9 alert("do while loop\n");
10 i = 1;
11 do
12 {
13 alert(i);
14 i++;
15 } while (i < 11);
16
17 alert("for loop\n");
18 for (int j = 1; j < 11; j++)
19 {
20 alert(j);
21 }