Style
li { /* all <li> elements */
property:value;
}
.my-class { /* all elements with class "my-class" */
property:value;
}
#my-id { /* element with id "my-id" */
property:value;
}
<script type="text/javascript" src="js/my-script.js"></script>
if, else)
statementsvar x = 13;
var str = "hello there";
var timesTwo = function(value) { return value * 2}
var arr = [13, 'fourteen', 15];
var obj = {name:'steve', job:'lobbyist'};
var characters = "This is a string"
characters.length // Returns the length of the variable
var arr = [1,2,3]
arr.length // Returns the number of items in the array
var chars = "This is a string"
chars.replace("This", "Here") // Replaces "This" with "Here"
var arr = [1,2,3]
arr.push(4)// Pushes 4 into the array as the last element
var num = 1;
typeof(num) // returns 'number'
var num = 1.2;
typeof(num) // returns 'number'
var num = 1e8
typeof(num) // returns 'number'
var num = 2*14 // num is 28
var num = 2/4 // num is .5
var num = Math.sqrt(4) // num is 2
var str = 'using single quotes'
var str = "using double quotes"
var name = "Mike"
var greeting = "Hello, my name is " + name // concatenation
var greeting2 = greeting.replace("Hello", "Sup") // replacing
var x = [13, 14, 15];
var x = ['one', 'two'];
var x = [13, 14]
x[0] // 13
x[1] // 14
var person = {
firstName:'Anna',
lastName:'Smith',
height:"5'4",
}
person.firstName // Anna
person['firstName'] // Anna
var person = {
firstName:'Anna',
favorites:{
music:'bluegrass',
food:'pizza'
}
}
person.favorites.food // 'pizza
var myFunction = function(a,b) {
return a*b
}
var result = myFunction(2,4) // returns 8
if(a<b) {
// execute some action
}
if(a<b) {
// take some action
}
else if(a==b) {
// another action
}
else {
// default
}
You have a function that compares values
var comparison = function(a,b) {
if(a>b) {
return 'a is greater that b'
}
else {
return 'b is less than or equal to a'
}
}
var comparison = function(a,b, callback) {
if(a>b) {
callback()
return 'a is greater that b'
}
}
var arr = [1,2,3]
var timesTwo = function(d) {return d*2}
var doubleArr = arr.map(timeTwo) // returns [2,4,6]
var arr = [1,2,3]
var doubleArr = arr.map(function(d) {
return d*2
})
var arr = [1,2,3]
var greaterThanTwo = arr.filter(function(d) {
return d>2
})
document.getElementById('my-input').value
document.getElementById("demo").style.fontSize = "25px";