-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.js
164 lines (107 loc) · 2.58 KB
/
functions.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
153
154
155
156
157
158
159
160
161
162
//Exercice 1
let number = Math.random();
console.log(number);
//Exercice 2
var numb = 12.42359;
numb = Math.round((numb + Number.EPSILON) * 100) / 100; // POURQUOI ?
console.log(numb);
//Exercice 3
var age = "35";
console.log(typeof(age));
age = parseInt(age);
console.log(age);
console.log(typeof(age));
//Exercice 4
var texte = "AXEL !";
var maxLength = 20;
console.log(`${texte} ${texte.length}`);
if (texte.length >= maxLength) {
console.log("Your texte is too long")
}
else {
console.log("OK")
}
//Exercice 5
var texte = "a nice boat"; //comment transformer un string en array.
console.log(typeof(texte))
const words = texte.split(" ");
console.log(words[2]);
const chars = texte.split('');
console.log(chars[8]);
const texteCopy = texte.split(" ");
console.log(texteCopy);
//Exercice 6
var name = "Paul Dumas";
var expectedName = "paul dumas";
name = name.toLowerCase();
if (name === expectedName) {
console.log("OK Paul you can come in");
}
else {
console.log("We do not know you");
}
//Exercice 7
var newStudent = "Ryan Oper"
var students = [
"Jhon Doe",
"Marc Alm",
"Jimmy Turner"];
console.log(typeof(newStudent))
console.log(typeof(students))
students.push(newStudent);
console.log(students);
students.push("Franck Martin", "Tom Hawkins");
console.log(students);
//Exercice 8
var transactions = [102, 51, 4563, 42, 78, 146, 10563];
var researched = 44;
if (researched === true) {
console.log("We found a matching transaction")
}
else {
console.log("No match")
}
console.log(transactions.includes(researched));
//exercice 9
var students = [
"Jhon Doe",
"Marc Alm",
"Jimmy Turner"];
students.sort();
console.log(students);
console.log(students[students.length-1]);
//Part 2
//Exercice 1
function prod(){
console.log("I am the product function");
return;
}
prod();
function product(a,b) {
return (a*b);
}
var result = product(4,30);
console.log(("The result of the function is : ") + result);
//Exercice 2
function showDigits() {
for (i=0; i <= 9; i++){
console.log(i);
}}
showDigits();
//Exercice 3
function welcome(firstname, lastName) {
return "Bienvenue " + firstname + " " + lastName;
}
var hello = welcome("paul", "Morea");
console.log(hello);
//Exercice 4
function isAdult(age) {
if (age => 18) {
age = true
console.log("true")}
else console.log("false")
if (age === true)
console.log("Welcome to the site")
else console.log("Not allowed to the site");
}
isAdult(19);