i started learning javascript and i decided to try to make a thing with modules, i want to loop from then and execute functions using a for loop!I know this is not the best way… but i learning okay?
document.addEventListener("DOMContentLoaded", function() {
//Pegamo o butão
const RunButton = document.getElementById("Run");
RunButton.addEventListener("click", () => {
// Fetch the JSON data
fetch('Codes.json')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
//Pegamos... o obvio né murilo!
const levelData = data[level];
//Blocks :)
const blocks = levelData.blocks;
// Loop pelo cade bloco e seu nome
for (let i = 0; i < levelData.BlocksIn; i++) {
//Block é o bloco atual!
const blockWord = blocks[i];
var Paramater = SectionDiv.querySelector("#Block_" + i);
// Pegamos o nome do bloco... e agora é so usar!
import('./blocks.js')
.then(module => {
//Pegamos do modulo
console.log("sex")
const FunctionOrClass = module.default[blockWord];
//Cria uma instacia ( pois é uma classe )
const Class = new FunctionOrClass()
//E executa uma função :)
Class[Paramater.value]()
alert(Paramater.value )
})
.catch(error => {
console.error('Error importing module:', error);
});
}
})
.catch(error => {
console.error('Error fetching JSON:', error);
});
});
});