Closed MaxKaye closed 8 years ago
can you post a link to your repo here and identify the lines you want to optimize?
http://github.com/MaxKaye/project1/blob/master/flashcard.html
I see what you mean! How about something like this, eliminating the need to copy and paste everything a zillion times:
var myCharacters = [
{english: "hello", chinese: "你好", pronounce: "ni3hao3"}
];
myCharacters.forEach(function(character){
var myText = document.createElement("INPUT");
var translate = document.createElement("BUTTON");
myText.value = character.chinese;
button.addEventListener("click", function(){
alert(character.english);
});
});
Thank you- this works AND exposes all the other structural problems in my code
I have completed the assignment by making my flashcards functional- however I know there have ways to make my code a lot more simple using less reused knowledge (e.g. current code is inline because had trouble linking external style sheets). I would like to learn how to re-express and reorganize what I currently have into a more object-oriented approach.
I have tried a few other ways of creating the same solution but nothing else is working.