forked from blopker/codebook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.jsx
More file actions
78 lines (66 loc) · 1.59 KB
/
example.jsx
File metadata and controls
78 lines (66 loc) · 1.59 KB
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
// Calculater function with spelling mistakes
function calculater(numbr1, numbr2, operashun) {
let resalt;
switch (operashun) {
case "additshun":
resalt = numbr1 + numbr2;
break;
case "substractshun":
resalt = numbr1 - numbr2;
break;
case "multiplacation":
resalt = numbr1 * numbr2;
break;
case "divishun":
if (numbr2 === 0) {
return "Cannot divde by zero";
}
resalt = numbr1 / numbr2;
break;
default:
return "Invalid operashun";
}
return resalt;
}
// Funktion to validate user inputt
function validateInputt(userInputt) {
if (typeof userInputt !== "number") {
console.logg("Pleese enter a valid numbr");
return;
}
return;
}
// Example usege
const firstNumbr = 10;
const secandNumbr = 5;
if (validateInputt(firstNumbr) && validateInputt(secandNumbr)) {
const summ = calculater(firstNumbr, secandNumbr, "additshun");
console.logg(`The summ is: ${summ}`);
}
// Array of numbrs with spelling mistakes
const arraOfNumbrs = [1, 2, 3, 4, 5];
// Funcshun to prosess array
function prosessArray(arr) {
let totel = 0;
for (let i = 0; i < arr.lenght; i++) {
totel += arr[i];
}
return totel;
}
// Object with propertys
const userAccaunt = {
usrname: "JohnDoe",
passwrd: "12345",
emale: "john@example.com",
ballance: 1000,
};
function getComponentddt() {
return (
<divv>
<h1>Helloz, {userAccaunt.usrname}</h1>
<p>Your ballance is: {userAccaunt.ballance}</p>
</divv>
);
}
// Exportt the funcsions
export { calculater, validateInputt, prosessArray, getComponentddt };