Created
January 20, 2019 15:42
-
-
Save designlobby/25fa027e57610b05889197c733bbc74b to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/dawifos
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
// 1. Create a variable with your name | |
var name = 'Design Lobby'; | |
console.log( name ); | |
// 2. Create a function that logs your name with console.log() | |
function logName( parameter ) { | |
console.log( parameter ); | |
} | |
logName( 'Design Lobby' ); | |
// 3. Create an object called "me" that includes properties for your first and last names as well as other properties for your website and social media | |
var me = { | |
first: 'Gareth', | |
last: 'Lockton', | |
website: 'https://designlobby.co.uk', | |
socialMedia: { | |
twitter: '@designlobby', | |
facebook: 'designlobby' | |
} | |
}; | |
console.log( me.socialMedia.twitter ); | |
// 4. Create a boolean variable called loggedIn (set to either true or false) | |
var loggedIn = false; | |
console.log( loggedIn ); | |
// 5. Write a conditional statement that logs "Logged In" when loggedIn is true and "Please login" when loggedIn is false | |
if ( loggedIn === true ) { | |
console.log( 'Logged In' ); | |
} else { | |
console.log( 'Please login' ); | |
}; | |
// 6. Create an array called ids filled with numbers that could represent post ids | |
var postIds = [11, 22, 33, 44, 55]; | |
// 7. Loop over the ids and log them all out | |
for (var count = 0, max = postIds.length; count < max; count++) { | |
console.log(postIds[count]); | |
} | |
// for of loop example | |
// for (var id of postIds) { | |
// console.log(id); | |
// } | |
// 8. Create an array of post objects. Include an id, title and content property on each object | |
var postObj = [ | |
{ | |
id: 1, | |
title: 'Title 1', | |
content: 'Content 1' | |
}, | |
{ | |
id: 2, | |
title: 'Title 2', | |
content: 'Content 1' | |
}, | |
{ | |
id: 3, | |
title: 'Title 3', | |
content: 'Content 3' | |
} | |
]; | |
// 9. Loop over the array of posts and log out the title of each one | |
for (var count = 0, max = postObj.length; count < max; count++) { | |
console.log(postObj[count].title); | |
} | |
// for of loop example | |
// for (var post of postObj) { | |
// console.log(post.title); | |
// } | |
// 10. Create a function that will take an array of posts and log out the title and content of each post. | |
function myFunction( postObj ){ | |
for (var count = 0, max = postObj.length; count < max; count++) { | |
var post = postObj[count]; | |
console.log(post.title); | |
console.log(post.content); | |
} | |
} | |
myFunction(postObj); | |
// for of loop example | |
// function logPostsExample2(posts) { | |
// for (var post of posts) { | |
// console.log(post.title); | |
// console.log(post.content); | |
// } | |
// } | |
// logPostsExample2(posts); | |
// 9. Loop over the array of posts and log out the title of each one | |
// 10. Create a function that will take an array of posts and log out the title and content of each post. | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">// 1. Create a variable with your name | |
var name = 'Design Lobby'; | |
console.log( name ); | |
// 2. Create a function that logs your name with console.log() | |
function logName( parameter ) { | |
console.log( parameter ); | |
} | |
logName( 'Design Lobby' ); | |
// 3. Create an object called "me" that includes properties for your first and last names as well as other properties for your website and social media | |
var me = { | |
first: 'Gareth', | |
last: 'Lockton', | |
website: 'https://designlobby.co.uk', | |
socialMedia: { | |
twitter: '@designlobby', | |
facebook: 'designlobby' | |
} | |
}; | |
console.log( me.socialMedia.twitter ); | |
// 4. Create a boolean variable called loggedIn (set to either true or false) | |
var loggedIn = false; | |
console.log( loggedIn ); | |
// 5. Write a conditional statement that logs "Logged In" when loggedIn is true and "Please login" when loggedIn is false | |
if ( loggedIn === true ) { | |
console.log( 'Logged In' ); | |
} else { | |
console.log( 'Please login' ); | |
}; | |
// 6. Create an array called ids filled with numbers that could represent post ids | |
var postIds = [11, 22, 33, 44, 55]; | |
// 7. Loop over the ids and log them all out | |
for (var count = 0, max = postIds.length; count < max; count++) { | |
console.log(postIds[count]); | |
} | |
// for of loop example | |
// for (var id of postIds) { | |
// console.log(id); | |
// } | |
// 8. Create an array of post objects. Include an id, title and content property on each object | |
var postObj = [ | |
{ | |
id: 1, | |
title: 'Title 1', | |
content: 'Content 1' | |
}, | |
{ | |
id: 2, | |
title: 'Title 2', | |
content: 'Content 1' | |
}, | |
{ | |
id: 3, | |
title: 'Title 3', | |
content: 'Content 3' | |
} | |
]; | |
// 9. Loop over the array of posts and log out the title of each one | |
for (var count = 0, max = postObj.length; count < max; count++) { | |
console.log(postObj[count].title); | |
} | |
// for of loop example | |
// for (var post of postObj) { | |
// console.log(post.title); | |
// } | |
// 10. Create a function that will take an array of posts and log out the title and content of each post. | |
function myFunction( postObj ){ | |
for (var count = 0, max = postObj.length; count < max; count++) { | |
var post = postObj[count]; | |
console.log(post.title); | |
console.log(post.content); | |
} | |
} | |
myFunction(postObj); | |
// for of loop example | |
// function logPostsExample2(posts) { | |
// for (var post of posts) { | |
// console.log(post.title); | |
// console.log(post.content); | |
// } | |
// } | |
// logPostsExample2(posts); | |
// 9. Loop over the array of posts and log out the title of each one | |
// 10. Create a function that will take an array of posts and log out the title and content of each post.</script></body> | |
</html> |
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
// 1. Create a variable with your name | |
var name = 'Design Lobby'; | |
console.log( name ); | |
// 2. Create a function that logs your name with console.log() | |
function logName( parameter ) { | |
console.log( parameter ); | |
} | |
logName( 'Design Lobby' ); | |
// 3. Create an object called "me" that includes properties for your first and last names as well as other properties for your website and social media | |
var me = { | |
first: 'Gareth', | |
last: 'Lockton', | |
website: 'https://designlobby.co.uk', | |
socialMedia: { | |
twitter: '@designlobby', | |
facebook: 'designlobby' | |
} | |
}; | |
console.log( me.socialMedia.twitter ); | |
// 4. Create a boolean variable called loggedIn (set to either true or false) | |
var loggedIn = false; | |
console.log( loggedIn ); | |
// 5. Write a conditional statement that logs "Logged In" when loggedIn is true and "Please login" when loggedIn is false | |
if ( loggedIn === true ) { | |
console.log( 'Logged In' ); | |
} else { | |
console.log( 'Please login' ); | |
}; | |
// 6. Create an array called ids filled with numbers that could represent post ids | |
var postIds = [11, 22, 33, 44, 55]; | |
// 7. Loop over the ids and log them all out | |
for (var count = 0, max = postIds.length; count < max; count++) { | |
console.log(postIds[count]); | |
} | |
// for of loop example | |
// for (var id of postIds) { | |
// console.log(id); | |
// } | |
// 8. Create an array of post objects. Include an id, title and content property on each object | |
var postObj = [ | |
{ | |
id: 1, | |
title: 'Title 1', | |
content: 'Content 1' | |
}, | |
{ | |
id: 2, | |
title: 'Title 2', | |
content: 'Content 1' | |
}, | |
{ | |
id: 3, | |
title: 'Title 3', | |
content: 'Content 3' | |
} | |
]; | |
// 9. Loop over the array of posts and log out the title of each one | |
for (var count = 0, max = postObj.length; count < max; count++) { | |
console.log(postObj[count].title); | |
} | |
// for of loop example | |
// for (var post of postObj) { | |
// console.log(post.title); | |
// } | |
// 10. Create a function that will take an array of posts and log out the title and content of each post. | |
function myFunction( postObj ){ | |
for (var count = 0, max = postObj.length; count < max; count++) { | |
var post = postObj[count]; | |
console.log(post.title); | |
console.log(post.content); | |
} | |
} | |
myFunction(postObj); | |
// for of loop example | |
// function logPostsExample2(posts) { | |
// for (var post of posts) { | |
// console.log(post.title); | |
// console.log(post.content); | |
// } | |
// } | |
// logPostsExample2(posts); | |
// 9. Loop over the array of posts and log out the title of each one | |
// 10. Create a function that will take an array of posts and log out the title and content of each post. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment