Created
December 6, 2015 10:13
-
-
Save AS87-code/97de617f45b1237a8489 to your computer and use it in GitHub Desktop.
JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="1.js" async> ..кто первый того и тапки | |
<script src="1.js" defer> ..в строгом порядке + ждет загрузки документа |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
условие ? значение1 : значение2 | |
message = (login == "Vasya") ? "hi" : | |
(login == "Director") ? "Hello" : | |
(login == "nologin") ? "Hello Gy" : | |
""; | |
*** | |
nextPrime: | |
for (var i = 2; i < 10; i++) { | |
for (var j = 2; j < i; j++) { | |
if (i % j == 0) continue nextPrime; | |
} | |
alert( i ); // простое | |
} | |
*** | |
while (условие) { | |
// код, тело цикла | |
} | |
— бесконечный цикл | |
while (true) { | |
// ... | |
} | |
— вывод пока меньше 3 | |
var i = 0; | |
while (i < 3) { | |
alert( i ); | |
i++; | |
} | |
*** | |
do { | |
// тело цикла | |
} while (условие); | |
—сначала тело потом условие | |
var i = 0; | |
do { | |
alert( i ); | |
i++; | |
} while (i < 3); | |
*** | |
for (начало; условие; шаг) | |
— вывод нечетных чисел | |
for (var i = 2; i <= 10; i++) { | |
if (i % 2 == 0) { | |
alert( i ); | |
} | |
} | |
*** | |
outer: for (var i = 0; i < 3; i++) { ..первый цикл | |
for (var j = 0; j < 3; j++) { ..второй внутри первого | |
var input = prompt('Значение в координатах '+i+','+j, ''); ..вывод в обоих | |
// если отмена ввода или пустая строка - | |
// завершить оба цикла | |
if (!input) break outer; // (*) ..завершение первого через второй | |
} | |
} | |
alert('Готово!'); | |
*** | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
модальное окно с полем для ввода | |
var year = prompt('how old are you?', 100); | |
alert ('you ' + year + ' old'); | |
*** | |
модальное окно с выбором действий | |
var isAdmin = confirm('You are admin?'); | |
alert(isAdmin); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment