-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathscript.js
152 lines (117 loc) · 2.9 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//Hello world
console.log('Hello World!!');
//Variable Exercises
var x = 8;
let y = 2;
const z = 6;
console.log(x, y, z);
x = 9;
y = 7;
//z = 15;
console.log(x, y, z);
console.log(a); //undefined
var a = 4;
//-------Definition of number---------
var num1 = 6;
var num2 = 4;
console.log(num1 === num2); //false
console.log(num1 === num2); //false
//Difference between == and ===
var num = 2;
var str = "2";
console.log("iki eşittir : ", num == str); //true
console.log("üç eşittir : ", num === str); //false
var result = num1 + num2;
console.log(result); //OUTPUT: 10
var float1 = 2.5;
var float2 = 5;
console.log(float1 + float2); // OUTPUT: 7.5
//-------Definition of string---------
var firstName = 'ilknur';
console.log(firstName); //OUTPUT: ilknur
var surname = 'dogan';
console.log(surname); // OUTPUT: dogan
var fullName1 = firstName + surname;
console.log(fullName1); // OUTPUT: ilknurdogan
//Old usage
var fullName2 = firstName + ' ' + surname;
console.log(fullName2); // OUTPUT: ilknur dogan
//New usage
var fullName3 = `${firstName} ${surname}`; //Backticks Windows: "AltGr ," Mac: "option +" are use to define "template literals"
console.log(fullName3); // OUTPUT: ilknur dogan
//Old usage
let eskiString = "En sevdiğim yemekler:\nİskender\nMantı"
//New usage
let yeniString = `En sevdiğim yemekler:
İskender
Mantı`
//-------Array-------
var simpleArray = [1, 2, 3, 4, 5];
console.log(simpleArray); // OUTPUT: [1, 2, 3, 4, 5]
console.log(simpleArray[0]); // OUTPUT: 1
console.log("simpleArray'in uzunluğu: " + simpleArray.length); // OUTPUT:5
var array = [1, 'pau', 2, [4, 5, 6]]; // Arrays can include different type of variables.
console.log(array[3]); // OUTPUT:[4, 5, 6]
console.log(array.indexOf('pau')); // OUTPUT: 1
//------Conditions------
//* if
var grade = 88;
if (grade < 50) {
console.log('Üzgünüm, dersten kaldın!');
} else if (grade > 50 && grade < 60) {
console.log('Dersi koşullu geçtin!');
} else {
console.log('Tebrikler, dersi geçtin!');
}
var weather = 'raining';
weather === 'raining' ? console.log('umbrella') : console.log('nothing');
//* while
var counter = 1;
while (counter <= 5) {
console.log('Sayaç: ' + counter);
counter++; //counter+=1
}
//* do-while
var number = 1;
do {
console.log('Number: ' + number);
number++;
} while (number <= 5);
//OUTPUT:
// Number:1
// Number: 2
// Number: 3
// Number: 4
// Number: 5
//* for
var colors = ['purple', 'blue', 'white'];
for (var i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
//* switch-case
var day = 3;
switch (day) {
case 1:
console.log('Monday');
break;
case 2:
console.log('Tuesday');
break;
case 3:
console.log('Wednesday');
break;
case 4:
console.log('Thursday');
break;
case 5:
console.log('Friday');
break;
case 6:
console.log('Saturday');
break;
case 7:
console.log('Sunday');
break;
default:
console.log('ERROR');
}