����� 5
�� 3: ������ ����� ������.
��� ������� �� ������ ����� �������. ���� ��� �� ����� ����� �� �������, ������� ��������, �������� ������, ��� ������ ���� ������ �������� �� JavaScript ���� �� ��� ������� ���� ������. ����� ����� ������ �������� �� JavaScript ����� ������ ��� ��������� ������ ��������� ����, ���� ����� ����� ������� ��� ������. ��� ���� ����� ������ ��� ���� ������ ���� ��� �� �����:
����� ����� ������ �� ��������.
������ �� ����� �� �� ����� ����� �� ���� ������ �� �������� �� ��������� ����� ����� ������� ���� ������ �� JavaScript ���� ������ ����� ����. �"� ����� ���� ����� ������ ����� �� ������ ���� ������� ����������, ���� ������ ����� ������� �� ���� �����������. ������, ��� ���� �� ������� ��� ������� ����� ���� ��� ����� ������� �������� �� �������� ��� ������ (my_variable, the_date, an_example_variable). ��� ��, ��� ����� ������ ����� ���� ����� ��������� (����: ()addThreeNumbers �� ()writeError ������). ��� ���� ������ ����� �� ���, ������ ���� ���� ���� ���� ������ �� ���� ����� ������ ����.
����� ����� ������ ������.
���� ����� ��� ���� ������ ���� ������� ���� ��� ��� ������ �"� JavaScript. ������, ���� ���� ��� ������ �� ��� "if" ���� ���� ��� ��� ���� �- JavaScript � �� ����� �- "if", ���� ����� ���� �������. ���� ������ ����� ���� ������, �� ��� ���� ����� ������ ��� "if", ��� ������ ��� "document" (����) ��� ���� ����� ���� ���� ����. �����, "document" ���� ������� �-JavaScript. ���� ���� ��� ������� �� ������ ������, ��� ������ ����� ���� ��� ��� "name" (��) (�������� �� ���� �� "names"). ����� ������ ��� "name" �� ���� ����� �����, �� ������, �� ����� ���� �� ����� ���� ������.
����� ����, �������� ����� �� ����� ������ �����, �� ���� ��� ��� ������ ���� ����� ����� �� ������. ����� ������ ����� ����� ��� ������ ������ ��� ����� �-JavaScript ����� ��� �-HTML. �� �� �� ���� �� ����� ����� ����� ����� �� �� ����, ��� ����� �� �� ������. �� �� ����, �� ������ ����� ����� �����.
�� ����� �� �� ���� ���� ����� ���� ������ ������.
���� ������� ��� ������ ����� ��, ��� ���� ���. �� ���� ����� ���� ���� ���� ����� ���� �� ������ ���� ����� ���� �����. ���� �����:
var the_name = prompt("what's your name?", "");
if (the_name = "the monkey")
{
alert("hello monkey!");
} else {
alert("hello stranger.");
}
��� �� ���� �� ������ "!hello monkey" ����� ������, ��� ���� �� ����� �- prompt, ��� ����� ����. ���� ��� �� ���� ���� ��� ������ if-then, ��� ����� �-JavaScript ���� ���� ���� ���� ��� ������ ��� ������. ���� �� ��� ����� "Robbie the robot" �� �- prompt. ������, the_name ���� "Robbie the robot". ��� �� �� ����� �- "if" ����� �-JavaScript ���� ���� ����� �� the_name = "the monkey". �� JavaScript ����� ���� �� ������, ����� ����� "���" ("true") �� �- if-then statement, ����� ������ ����� �� ����� "!Hello monkey" ����.
���� ������� ���� ���� ����, �� ����� ������ ����� ���� ���.
���� ������ �������� �����, �� ����� ���� �������� �������.
���� �� ����� ���� ��� ����. ���� ������ �-JavaScript ����� ������ ��� ����� ������� ��� �"� �� ��������� �� ������� ����� �������� ���. ��� ����� �����:
var the_name = 'koko the gorilla';
alert("the_name is very happy");
���� ������ ����� "the_name is very happy", ����� �- the_name ��� �����. ��� ����, ����� �- JavaScript ���� ������� ���� ����, ��� ������ ����� �������, ��"� �� ����� �� the_name ���� �������, ����� �- JavaScript ������ ���� �� ������ �������.
���� ����� ���� ����� ������� �� ��� �� (��� ����� ���� ������- ����):
function wakeMeIn3()
{
var the_message = "Wake up! Hey! Hey! WAKE UP!!!!";
setTimeout("alert(the_message);", 3000);
}
����� ��� ���� ���� �-JavaScript ������ �� alert(the_message) ���� ���� �����. ���� ����� ������, ��� ����, the_message ���� ����� ���� ���� ����� ���������. ������ ����� �� ���:
function wakeMeIn3()
{
var the_message = "Wake up!";
setTimeout("alert('" + the_message+ "');", 3000);
}
�"� ����� the_message ���� �������� ����� ���, ������ "alert('Wake up!');" ����� �"� �-setTimeout, ��� ������.
���� ����� ������� ���� ����, ����� ���� ��� ������. ���� ����� �� ������ ���, ���� ����� ����� ����� ���� ����. �����, ��� ���� �� �� ����� �������� ���������.
���� ������ ���
��� ��� «--
|