forked from taiansu/astro_04_js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday1.js
136 lines (113 loc) · 2.5 KB
/
day1.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
let a = 10;
let b = 20;
let result = a + b;
let a5 = "1";
let b6 = 2;
let result7 = a5 + b6;
// console.log(result7);
let ary = [1, 2, 3, 4, 5];
// console.log(typeof ary)
for (var i = 0; i < 10; i++) {
// do something
}
// console.log(i);
// camelCase
let myAweseomVariable = 10;
// function
/*
multi
line
comment
*/
function foo(num) {
console.log(num + 1);
}
// foo(10)
function bar() {
console.log("hohoho");
}
// bar()
// define a function call getMax, print the max number pass in
// 可以用 $, _, 英文字母開頰
// 接著可以用數字
function getMax(n1, n2, n3, n4, n5, n6) {
console.log("n1:", n1);
console.log("n2:", n2);
// let res = Math.max(n1, n2, n3, n4, n5, n6)
// console.log('res:', res)
// console.log(Math.max(n1, n2, n3))
}
let aary = [1, 2, 3, 4, 5, 6];
// getMax(aary) // => "6"
function addOne(x) {
// console.log('lalala')
return x + 1;
}
// console.log(addOne(100))
// 定義一個接收兩個數字的函式,會回傳將兩個數字相加的結果
function add(x, y) {
return x + y;
}
// 呼叫函式並印出來
let res64 = add(5, 6);
// console.error(res64)
function badAdd(i) {
if (i % 2 === 0) {
return "noooo";
} else {
return i + 1;
}
}
function badReturn(userName, number) {
return `Hello, ${userName}, I just received the nubmer ${number} you gave me`;
}
// console.log('badReturn(100): ', badReturn(100))
// console.log('a2' < 'a1')
let num1 = 1;
let str1 = "1";
// console.log('==: ', num1 == str1)
// console.log('===: ', num1 === str1)
// console.log('0 == false:', 0 == false)
// console.log('NaN == NaN', NaN == NaN)
var someVariable;
// console.log(someVariable);
// console.log(someVariable === null);
// console.log("Hello, ${username}, I receive ${number}")
// if...else
// let bool89 = 10 < 18
let numA = 0;
if (numA) {
console.log("lalala");
console.log("hohoho");
} else {
console.log("no way");
}
// falthy value:
// false, undefined, null, 0, '', []
// Ruby falthy value:
// nil, false
// else if
// if(cond1) {
// } else if(cond2) {
// } else if(cond3) {
// } else { }
// 寫一個叫 calculate 的函式,接收一個數字
// 超過一千打八折,超過一百打八五折,其它九折。
// 回傳計算後的總價
function getDiscountRate(num) {
if (num > 1000) {
return 0.8;
} else if (num > 100) {
return 0.85;
} else {
return 1;
}
}
function getTaxRate() {
return 1.05
}
function clac(num) {
return num * getDiscountRate(num) * getTaxRate();
}
consol.log(clac(2000));
// SO(open close)LID