Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Class5/intermediate.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
89 lines (67 sloc)
1.5 KB
This file contains 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
function checkForm() { | |
var formCount = document.forms.length; | |
if(formCount > 0) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
// AND/OR | |
var bool1 = true; | |
var bool2 = false; | |
if(bool1 && bool2) { | |
console.log("AND"); | |
} else if(bool1 || bool2 && 1 > 3) { | |
console.log("OR"); | |
} | |
// Ternary operators | |
var result = (bool1) ? "The expression is true" : "The expression is false"; | |
console.log(result); | |
var personInfo = { | |
firstName: "Joe", | |
lastName: "Smith", | |
state: "CT", | |
zipCode: "06111", | |
fullName: function() { | |
return this.firstName + " " + this.lastName; | |
} | |
}; | |
//JSON | |
var json = { | |
"firstName": "Joe", | |
"lastName": "Smith", | |
"state": "CT" | |
}; | |
JSON.stringify(personInfo); | |
console.log(personInfo.firstName); | |
console.log(personInfo.fullName()); | |
var array = ["CT", "MA", "NY", "RI", "NH", "VT", "ME"]; | |
console.log(array.length); | |
var name = "Frank"; | |
var length = name.length; | |
array.push("PA"); | |
console.log(array); | |
array[0]; // "CT" | |
array[3]; // "RI" | |
delete array[1]; | |
console.log(array); | |
array.splice(1, 1); | |
// var array = ["CT", "MA", "NY", "RI", "NH", "VT", "ME"]; | |
//foreach | |
array.forEach(function(item) { | |
console.log(item + "!"); | |
}) | |
//DATES | |
personInfo.createdDate = new Date(); | |
var date = new Date(); | |
console.log(date); | |
var stringDate = new Date("02/24/2020"); | |
var something = new Array(); | |
//Try/Catch | |
try { | |
if(something.length > 0) { | |
alert('The array exists'); | |
} | |
} catch { | |
console.log("There was an error in your try/catch"); | |
} |