Closed jasonvandewarker closed 7 years ago
Could you pop all the answers to the code pens in here please?
Sure can! Sorry about that! Q1
What is the function of document.getElementById()? It prints the input to the HTML based on the HTML element id.
What happens if you remove e.preventDefault()
on line 18 and return false
on line 37? (Delete these lines and play around with the app) Why does this happen? (Search 'e.preventDefault form' on Google)
The text is not captured. preventDefault cancels the default behavior of the browser, which in this case is to not capture the input.
How do you grab the value of an input element using JavaScript? With the document.getElementById method and then storing the value in a variable.
How do you set the innerHTML of a p element using JavaScript? By calling the ID from the p element and using document.getElementById method.
Q2
What is the function of appendChild()? It makes a node the last child of a node.
What is the function of createElement()? createElement creates the element that can then be filled with content from something like appendChild.
What is the function of createTextNode()? createTextNode creates a node that can then be filled with the specified text.
How would you go about implementing a remove todo feature? We would need to create another button for the remove feature. Instead of taking the value from the input, this button would need a clickevent that would find the last
Q3
What is the function of document.getElementsByTagName? It returns all the element's child elements, and does it as a nodeList object that can be accessed by index numbers.
What is the purpose of the .reduce function? This function reduces all of the numbers in an array down to one number, which is the same as adding them all together and creating a sum of all the numbers.
What is the purpose of the setAttribute method? It adds the attribute node to an element, but if it already exists then it replaces it.
I'm going to re-write Q2, 4 since it printed the html tags I used. I should have known that!
We would need to create another button for the remove feature. Instead of taking the value from the input, this button would need a clickevent that would find the last li in the parent ul and remove it. removeAttribute() would work I think, but it would probably erase all the li, instead of just the last one.
Problem 1 http://codepen.io/jasonvandewarker/pen/eWZeRd
Problem 2 http://codepen.io/jasonvandewarker/pen/LyNeNM
Problem 3 (did my best, but it definitely still doesn't work.) http://codepen.io/jasonvandewarker/pen/BRzjxz