-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
136 lines (92 loc) · 3.49 KB
/
Copy pathmain.js
File metadata and controls
136 lines (92 loc) · 3.49 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
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
//tecla Pom
/*function tocaSomPom () {
document.querySelector('#som_tecla_pom').play();
}
document.querySelector('.tecla_pom').onclick = tocaSomPom;
//tecla clap
function tocaSomClap () {
document.querySelector('#som_tecla_clap').play();
}
document.querySelector('.tecla_clap').onclick = tocaSomClap;
//tecla Tim
function tocaSomTim () {
document.querySelector('#som_tecla_tim').play();
}
document.querySelector('.tecla_tim').onclick = tocaSomTim;
//tecla Puff
function tocaSomPuff () {
document.querySelector('#som_tecla_puff').play();
}
document.querySelector('.tecla_puff').onclick = tocaSomPuff;
//tecla Splash
function tocaSomSplash () {
document.querySelector('#som_tecla_splash').play();
}
document.querySelector('.tecla_splash').onclick = tocaSomSplash;
//tecla Toim
function tocaSomToim () {
document.querySelector('#som_tecla_toim').play();
}
document.querySelector('.tecla_toim').onclick = tocaSomToim;
//tecla Psh
function tocaSomPsh () {
document.querySelector('#som_tecla_psh').play();
}
document.querySelector('.tecla_psh').onclick = tocaSomPsh;
//tecla Tic
function tocaSomTic () {
document.querySelector('#som_tecla_tic').play();
}
document.querySelector('.tecla_tic').onclick = tocaSomTic;
//tecla Tom
function tocaSomTom () {
document.querySelector('#som_tecla_tom').play();
}
document.querySelector('.tecla_tom').onclick = tocaSomTom;
document.querySelectorAll('.tecla');
/*criando referencia - (reduzindo referencia da linha)deve utilizar a palavra reserva-da const. A palavra const vem de "constante", ou seja, algo que nunca muda.
Então criar um nome para essa lista(para guardar a lista de botoes)
Para armazenar um valor na referencia criada, utilize o comando de atribuição =.
Conclusão:a lista de elementos encontrada por meio do método de busca
querySelectorAll será armazenada na referência listaDeTeclas.*/
//Declarar e chamar a função, executar o som através do play
/*
querySelector para selecionar elementos
concede o acesso ao código, atribuir para tocar o som*/
function tocaSom (seletorAudio) {
const elemento = document.querySelector(seletorAudio);
if (elemento && elemento.localName === 'audio') {
elemento.play();
}
else {
//alert('Elemento não encontrado');
console.log('Elemento não encontrado ou seletor inválido');
}
}
const listaDeTeclas = document.querySelectorAll('.tecla');
//para
for (let contador = 0; contador < listaDeTeclas.length; contador++) {
const tecla = listaDeTeclas[contador];
const instrumento = tecla.classList[1];
const idAudio = `#som_${instrumento}`; //template string
tecla.onclick = function () {
tocaSom(idAudio);
}
//eventos do teclado onkeydowne onkeyup.
//adicionar e remover classes em um elemento HTML através do JavaScript, com as funções add e remove do classList.
tecla.onkeydown = function (evento) {
if (evento.code === 'Space' || evento.code === 'Enter') {
tecla.classList.add('ativa');
}
}
tecla.onkeyup = function () {
tecla.classList.remove('ativa');
}
}
/*Template string é uma forma de facilitar a exibição de texto no JavaScript,
ele permite agrupar textos (strings) com outros tipos de informação, como number, boolean, array, entre outros.
Estrutura de repetição for(significa para).
Estrutura condicional if(significa se).
Operador de igualdade ==, estritamente igual (===), e o operador or (||).
A estruturas condicionais if e else juntas.
O operador not equals (!=), operador lógico and (&&) e o valor null.*/