-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
162 lines (143 loc) · 4.41 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<title>Prueba Javascript</title>
<style>
.square{
width: 100px;
height: 100px;
}
.red {
background-color: red;
}
.blue {
background-color: blue;
}
</style>
</head>
<body>
<div id="parentDiv">
<div id="squareDiv" class="square red"> </div>
<button id="ChangeColorButton">Load Users</button>
</div>
<img id="imgLoad" src="" alt="">
<table>
<thead>
<tr>
<th>Nombre Completo</th>
</tr>
</thead>
<tbody id="userTable">
</tbody>
</table>
<script>
//ejemplo jason
$('#ChangeColorButton').click(function(event){
$.getJSON("https://mentoria12.segic.cl/",function(data){
console.log(data);
let names = data.map((user) =>user.firstname + " " + user.lastname);
console.log(names);
names.forEach(element => {
let trElement = "<tr><td>" + name + "</td></tr>";
$('#userTable').append(trElement);
});
});
});
/*$('#ChangeColorButton').click(function(event){
$.getJSON("https://aws.random.cat/meow?ref=public-apis",function(data){
// console.log(data);
$('#imgLoad')
.attr('src', data.file)
.fadeIn("slow")
.click(function(){
$("#imgLoad").fadeOut("slow");
});
});
});*/
//ejemplo uso de JS
/*
$('#ChangeColorButton').click(function(event){
if ( $('#squareDiv').hasClass('red')){
$('#squareDiv')
.removeClass('red')
.addClass('blue');
}else
$('#squareDiv')
.removeClass('blue')
.addClass('red');
});*/
/*
//ejemplo uso de DOM
document.getElementById('ChangeColorButton')
.addEventListener('click',function(){
// parar evento burbujeante (event Bubbling)
event.stopPropagation();
let divElement = document.getElementById('squareDiv');
if (divElement.classList.contains('red')){
divElement.classList.replace('red','blue');
}else{
divElement.classList.replace('blue','red');
}
});
document.getElementById('parentDiv')
.addEventListener('click',function(event){
console.log("yeah baby");
});*/
//Document Object Model
//axios y jquery (yii)
// Juego
var tasks = [
{
"name": "Estudiar Javascript",
"duracion": 60
},
{
"name": "Estudiar Vue",
"duracion": 150
},
{
"name": "Estudiar Laravel",
"duracion": 100
}
];
/*let taskName = [];
for (let i =0; i<tasks.length; i++){
taskName.push(tasks[i].name);
//console.log(tasks[i].name);
}
let taskNames = [];
tasks.forEach(function(task){
taskNames.push(task.name);
}); */
//map"transformacion"
// filter reduce "filtrar ciertos datos"
//arrow function JS PHP Dart
// (parametros) => return implicito
//let taskNames = tasks.map((task) => task.name);
/* //metodo 1
let difficultTasks =[];
tasks.forEach(function(task){
if (task.duracion >= 100) {
difficultTasks.push(task.name);
}
});*/
/*metodo 2
let difficultTasks =tasks.filter(function(task){
return task.duracion >= 100;
});
*/
//metodo 1+2
/*let difficultTasks = tasks.filter((task) => task.duracion >=100).map((task) => task.name);
console.log(difficultTasks);*/
let frutas = ['Manzana','Peras','Naranjas','Platano'];
let frutasEliminadas = frutas.splice(1,2,'Durazno','Uva');
console.log(frutas);
console.log(frutasEliminadas);
console.log(frutas.indexOf('Platano'));
</script>
</body>
</html>