console.log("Hello")
displays hello on the console
console.log("10");
console.log("Hi")
Missing semicolon
What is the event listener for allowing content to appear using a click of a button?
onclick();
Is an if statement a loop?
Yes
var x =5;
console.log(x);
displays 5 on the console
Create a variable with a value of 10. On a separate line, add 15 to this variable using assignment operators. Console.log the final variable.
<script>
var x = 10;
x += 15;
console.log(x);
</script>
variable x = 5;
Should be var instead of variable
What is the event listener for allowing content to appear with a hover from the mouse?
What is the length of the given string?
var string = "Hello World!"
The length of Hello World is 12 since the character includes the string.
var array=["apple", "pen", "applepen"];
console.log(array[1]);
displays pen in the console
Create a for loop that runs through the contents of an array and console.log each one.
var array = ["apples", "bananas", "oranges"];
for(var i = 0; i < array.length; i++){
console.log(array[i]);
}
var x = document.getElementByClassName("color");
Should be document.getElementsByClassName
What is the event listener for when a mouse hovers over a certain element and hovers off, a change occurs?
mouseout();
Part 1
How do you link a JavaScript file in the HTML?
Part 2
What tags do you use to put JavaScript in your HTML?
Part 1: <script src="filename.js">
Part 2: <script></script>
(Preferably outside the body tag)
<html><p class="text">words</p></html>
<script>
var words=document.getElementById("text");
words.innerHTML="words 2.0";
</script>
changes "words" to "words 2.0"
Add a new string to this array:
var array = ["red", "orange", "yellow"];
i.e. array.push("green");
Two errors:
var array = ("red, green, blue");What is the difference between onclick on click when used in an html file?
click is a function on HTML elements you can call to trigger their click handlers: element.click();.
onclick is a property that reflects the onclick attribute and allows you to attach a DOM handler to the element for when clicks occur.
What datatype is is being used when you make a store a class in a JS variable?
Array
<body><p class="words">hi</p> <p class="words">hello</p>
<p id="output"></p>
</body>
<script>var output=document.getElementById("output");
var text=document.getElementsByClassName("words");
for(var i=0; i<text.length; i++){
text[i].addEventListener("click", function(){
output.innerHTML="adios";
});
}</script>
Whenever you click the words "hello" or "hi", "adios" will pop up.
Create an onclick function called "change" that changes the text of a paragraph tag to "Web Development." and put it inside the paragraph tag.
<p id="text">Random Text</p>
<p id="text" onclick="change();">Random Text</p>
<script>
function change() {
var text = document.getElementbyID("text");
text.innerHTML = "Web Development";
}
Two errors:
var i;
for (i == 0; i < 5; i+) {
console.log("hello");
}
Type the code with the function "myFunction" for a "click" event listener.
element.addEventListener("click", myFunction);
How do you change the color of something using JS?
element.style.color="colorname"