Skip to content

Instantly share code, notes, and snippets.

View stevencombs's full-sized avatar

Steven B. Combs' Git stevencombs

View GitHub Profile
// Javascript Getting Started with Programming
// A Codecademy Javascript (…And the good!) assignment
// Dr. Steven B. Combs, coding novice
for (var x = 1; x < 21; x++){
if (x % 3 === 0 && x % 5=== 0){ // If number divisible by 3 and 5
console.log("FizzBuzz"); // Print 'FizzBizz'
}
else if (x % 3 === 0){ // If number divisible by 3
console.log("Fizz"); // Print 'Fizz' to the console
@stevencombs
stevencombs / JavascriptObjectConstructor.js
Last active December 22, 2015 18:59
Javascript Object Formatting
// Javascript Object Formatting Syntax
// Both code examples create the same object
// Dr. Steven B. Combs, coding novice
// Object Literal Notation
var me = {
name: 'Steven',
age: '48',
interests: ["coding", "running", "blogging"], // array
};
@stevencombs
stevencombs / JavascriptArrayUsage.js
Created September 7, 2013 17:14
Examples of Javascript array types and usage.
// Javascript Arrays
// Dr. Steven B. Combs, coding novice
// Define array
var languages = ["HTML", "CSS", "JavaScript", "Python", "Ruby"];
console.log(languages[2]); // Print third item in array
console.log(languages.length); // Print number of items in array
// Print contents of array a line at a time
// Divisible by Two, or any other value, Javascript function code
// Dr. Steven B. Combs, coding novice
var isDivisible = function(number) {
if (number % 2 === 0) { // Number 2 could be any value
return true; // Return true if value is divisible by 2
} else {
return false; // Return false if value is not divisible by 2
}
};
// Javascript Getting Started with Programming
// A Codecademy Javascript (Dragon Slayer!) assignment
// Dr. Steven B. Combs, coding novice
var slaying = true;
var youHit = Math.floor(Math.random() * 2); // random number between 0 and 1
var damageThisRound = Math.floor(Math.random() * 5 + 1); // random number between 1 and 5
var totalDamage = 0; // damage counter
while (slaying){
@stevencombs
stevencombs / ControlFlowExamples.js
Last active December 22, 2015 01:59
Various Javascript control flow examples.
// Javascript Getting Started with Programming
// A Codecademy Javascript (When to 'while' and when to 'for') assignment
// Dr. Steven B. Combs, coding novice
// For loop - use to repeat code a specific number of times
for(var i = 0; i < 3; i++){
console.log("Hello World!");
}
// While loop - use to repeat code until a specific condition is met
@stevencombs
stevencombs / index.html
Created August 30, 2013 23:45
A basic web layout using CSS. Taken from the Codecademy "Clearing elements" assignment.
<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
<title>Result</title>
</head>
<body>
<div id="header"></div>
<div class="left"></div>
<div class="right"></div>
@stevencombs
stevencombs / ClassExample.css
Last active December 21, 2015 16:49
Two files demonstrate the use of the class, id and pseudo-class selectors to apply style to all text within the body tags of the html file.
/* A Codecademy Web Fundamentals (CSS Selectors) assignment
Dr. Steven B. Combs, coding novice */
.fancy {
font-family: cursive;
color: violet;
}
#serious {
font-family: Courier;
@stevencombs
stevencombs / SearchTextForName.js
Last active December 21, 2015 16:49
Javascript code to search through a text string for specific text.
// Javascript Getting Started with Programming
// A Codecademy Javascript (Search Text For Name) assignment
// Dr. Steven B. Combs, coding novice
var text = "blah blah blah blah Steven \
blah blah blah blah Steven blah";
var myName = "Steven";
var hits = [];
for (var i = 0; i < text.length; i++){
// Javascript Getting Started with Programming
// A Codecademy Javascript (Loops and Arrays III) assignment
// Dr. Steven B. Combs, coding novice
// Assign array and variable
var array = [3, 6, 2, 56, 32, 5, 89, 32];
var largest = 0;
for (var i = 0; i < array.length; i++){ // Parse through array a single value at a time
if (array[i] > largest) { // Determine if the array element is larger than the last