object =
{
property1: value1,
property2: value2,
.
.
.
propteryN: valueN
}
object.property
they need to be a valid variable nameobject[property]
object = {}
object.newProperty = newValue;
var student = {
name: "Bryan Wilkinson",
courses: ["473, 478","671","679"],
"Proposal Title": "Improving the Computational Representation of Scalar Adjectives",
print: function(){
console.log("Hello")
}
}
student.name
student.courses
student.print()
student."Proposal Title"
student["Proposal Title"]
{
property1: value1,
property2: value2,
method1: function(){
doSomething(this.property1)
}
}
var object = {
propertyA: valueA,
propertyB: valueB
}
object.methodA = function(){ doSomething(this.propertyA)}
var student = {
name: "Bryan Wilkinson",
courses: ["473","478","671","679"],
"Proposal Title": "Improving the Computational Representation of Scalar Adjectives"
}
student.print = function(){
console.log(this.name + " has taken " + this.courses.join(", "))
}
student.print()
var studentPrototype = {
name: "I need a name",
courses: [],
addCourse: function(course){
this.courses.push(course)
},
print: function(){
console.log(this.name + " has taken " + this.courses.join(", "))
}
}
studentPrototype.print()
var bryan = Object.create(studentPrototype)
bryan.print()
bryan.name = "Bryan Wilkinson"
bryan.addCourse('679')
bryan.print()
studentPrototype.print()
function Student(name){
this.name = name
this.courses = []
this.addCourse = function(course){
this.courses.push(course)
},
this.print = function(){
console.log(this.name + " has taken " + this.courses.join(", "))
}
}
var bryan = new Student("Bryan Wilkinson")
bryan.addCourse("679")
bryan.print()
var bryan2 = new Student("Bryan Wilkinson")
bryan2.addCourse("673")
bryan2.print()
Person = {
name: "I need a name"
}
Student = {
course: []
}
Student.prototye = Object.create(Person)
String.prototype.alternate = function(){
var method = String.prototype.toUpperCase
var nextMethod = String.prototype.toLowerCase
var chars = []
for(var i = 0; i < this.length; i++){
var char = this[i]
chars.push(method.call(char))
var temp = method
method = nextMethod
nextMethod = temp
}
return chars.join('')
}
"abcdefg".alternate()
var str = "Test String"
String.prototype.getFirst = function(){
return this[0]
}
str.getFirst()
Array.prototype.dequeue = Array.prototype.shift
Array.prototype.dequeue2 = function(){
return this.shift()
}
var arr = [1,2,3,4]
arr.dequeue()
arr
arr.dequeue2()
arr
<!DOCTYPE html> <!-- Needed to indicate we are using HTML5 -->
<html>
<head>
<!-- Many Javascript includes go here -->
<script src="location"></script>
<!-- Can also write your own code here -->
<script>
console.log("This is JavaScript");
</script>
</head>
<body>
<h1>Document Definition</h1>
<p id="identifier">This is where we put the parts of the document</p>
</body>
</html>
%%html
<html>
<head>
<!-- Include a library, called underscore.js that has a shuffle function built in so I don' have to write one -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script>
var words = ['hot','cold','freezing','warm']
//Shuffle the words
words=_.shuffle(words)
//Add them to the container
for(var i = 0; i < words.length; i++){
document.querySelector("#container").insertAdjacentHTML("beforeend","<p>" + words[i] + "</p>")
}
</script>
</head>
<body>
<!-- This is where we are going to place the words -->
<div id="container">
</div>
</body>
</html>
%%html
<html>
<head>
<script>
document.querySelector("#here").insertAdjacentHTML("beforeend","Hello World!")
</script>
</head>
<body>
<div id="here">
</div>
</body>
</html>
%%html
<html>
<head>
<script>
var num = 1;
while(num < 11){
document.querySelector("#here2").insertAdjacentHTML("beforeend","<p>" + num * num + "</p>")
num++
}
</script>
</head>
<body>
<div id="here2">
</div>
</body>
</html>
%%html
<html>
<head>
</head>
<body>
<!-- A div is used to group a set of elements together -->
<div>
<p>The paragraph tag sets off different paragraphs of text from each other</p>
<h1>This is a level 1 heading</h1>
<h2>There are six levels of headings: 2</h2>
<h3>3</h3>
<h4>4</h4>
<h5>5</h5>
<h6>6</h6>
<p>Lists are made using the ol(ordered list) or ul(unordered list) tags</p>
<ol>
<li>This is good for an numbered outline</li>
<li>Or a set of instructions</li>
</ol>
<ul>
<li>UL creates items denoted with bullet points</li>
</ul>
</div>
<div>
<h2>Form Elements</h2>
<p>Form elements are used to collect input from a user. Originally this was always
sent to a server, but now we can respond to input using JavaScript, specificaly event. </p>
<label>This is a text box: </label> <input type="text"/>
<div>
<input type="button" value="This is one way to make a button"/>
<button>This is nicer I think</button>
</div>
<div>
<input type="radio"/><label>Radio Button</label>
<input type="radio"/><label>Radio Button</label>
<input type="radio"/><label>Radio Button</label>
</div>
<div>
<input type="checkbox"/><label>Checkbox</label>
<input type="checkbox"/><label>Checkbox</label>
<input type="checkbox"/><label>Checkbox</label>
</div>
<label>This is a dropdown</label>
<select>
<option>Option 1</option>
<option>Option 2</option>
</select>
</div>
<div>
<h2>Tables in HTML</h2>
<p> For a long time, tables were used in HTML for both data and page layout.
They should only ever be used to display data that belongs in a table.</p>
<table>
<!-- To specify table headers -->
<thead>
<tr>
<th>Heading 1</th>
<th>Heading 2</th>
<th>Heading 3</th>
</tr>
</thead>
<tbody>
<!-- TR is a table row -->
<tr>
<!-- TD is a table cell in a row -->
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
</tr>
<tr>
<!-- TD is a table cell in a row -->
<td>Row 2</td>
<td>Row 2</td>
<td>Row 2</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>