Last active
April 21, 2020 23:36
-
-
Save lindsaycarbonell/942012a991528ef9d859b41aa9f6793f to your computer and use it in GitHub Desktop.
MEJO 187 JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>JavaScript Practice</title> | |
<script src="js/main.js" type="text/javascript"></script> | |
<style> | |
/* css here*/ | |
</style> | |
<script> | |
//javascript here | |
</script> | |
</head> | |
<body> | |
<button id="demo-btn">Click me!</button> | |
<div id="demo-text"> | |
</div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.onload = e => { | |
//locate the demo button | |
var box = document.getElementById("demo-text"); | |
var btn = document.getElementById("demo-btn"); | |
var thisNumber; | |
//click the button | |
btn.addEventListener("click",function(){ | |
thisNumber = 5; | |
// console.log(thisNumber); | |
// console.log("you clicked the button!"); | |
box.innerHTML = "I love JavaScript!"; | |
}); | |
}; | |
function sayHello(name, age) { | |
console.log(`hello ${name}, you are ${age} years old.`); | |
} | |
sayHello("Lindsay", 25); | |
//function declaration | |
function generateGreeting(name, age) { | |
return `hello ${name}, you are ${age} years old.`; | |
} | |
//call the function | |
var thisName = "Lindsay"; | |
console.log(generateGreeting(thisName, 23)); | |
var thisGreeting = generateGreeting(thisName, 23); | |
console.log(thisGreeting); | |
function addFifty(num) { | |
var sum = num + 50; | |
console.log(sum); | |
} | |
function multiplyNums(num1, num2) { | |
var factor = num1*num2; | |
console.log(factor); | |
} | |
function returnFactor(num1, num2) { | |
return num1*num2; | |
} | |
var factor = returnFactor(3,4); //12 | |
console.log(factor); | |
var myName = "Lindsay Carbonell"; | |
var alma_mater = "UNC-CHAPEL HILL"; | |
var favFood = "Rice"; | |
var number = 3; | |
var anotherNumber = 67; | |
var isTrue = true; | |
var isFalse = false; | |
var isThisTrue = true; | |
var name = "Lindsay"; | |
var age = 25; | |
var myFavoriteFood = "pizza"; | |
//template literals | |
// console.log( | |
// `My name is ${name}. I am ${age - 5} years old and I love to eat ${myFavoriteFood}.` | |
// ); | |
//String concatenation | |
// console.log("My name is " + name + ". I am " + (age - 5) + " years old."); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment