Skip to content

Instantly share code, notes, and snippets.

View krcrawford's full-sized avatar

Kyle Crawford krcrawford

  • McKinney, TX, USA
View GitHub Profile
@krcrawford
krcrawford / render.js
Created March 9, 2019 00:23
VDOM - render
const render = (vNode) => {
if (typeof vNode === 'string') {
return document.createTextNode(vNode);
}
const { tagName, attrs, children } = vNode;
const el = document.createElement(tagName);
for (const [k, v] of Object.entries(attrs)) {
if (/^on/.test(k)) {
const eventType = k.replace(/^on/, '').toLowerCase();
el.addEventListener(eventType, v);
@krcrawford
krcrawford / createElement.js
Created March 9, 2019 00:15
VDOM - create
const createElement = (tagName, { attrs, children }) => {
const vEl = Object.create(null);
Object.assign(vEl, {
tagName,
attrs,
children,
});
return vEl;
}
@krcrawford
krcrawford / tic-tac-toe.css
Created March 7, 2019 15:48
Javascript Homework #8 CSS
h1 {
display: block;
text-align: center;
}
#board {
display: block;
width: 156px;
height: 156px;
border: 1px solid #000000;
@krcrawford
krcrawford / tic-tac-toe.js
Created March 7, 2019 15:47
Javascript Homework #8 JS
const startGame = () => {
let team = 'X';
const board = [
['-', '-', '-'],
['-', '-', '-'],
['-', '-', '-'],
];
const updateBoard = (id) => {
switch (id) {
case 'tl':
@krcrawford
krcrawford / tic-tac-toe.html
Last active March 7, 2019 15:46
Javascript Homework #8 HTML
<html>
<head>
<title>Tic-Tac-Toe</title>
<script src="tic-tac-toe.js"></script>
<link rel="stylesheet" type="text/css" href="tic-tac-toe.css">
</head>
<body>
<h1>Tic-Tac-Toe</h1>
<div id="board">
<div class="row">
@krcrawford
krcrawford / dom.html
Last active March 7, 2019 12:20
Javascript Homework #7
<html>
<head>
<title>DOM Homework Page</title>
<style>
#rectangleWrapper {
padding-top: 50px;
padding-left: 50px;
padding-right: 50px;
padding-bottom: 0;
}
@krcrawford
krcrawford / fizzbuzz.js
Created March 6, 2019 21:28
Javascript Homework #6
const fizzbuzz = () => {
let index = 0, max = 100, log = '';
const initialPrimes = [2, 3, 5, 7, 11];
for (; index < max; index++) {
if ((index !== 1 && initialPrimes.indexOf(index) !== -1) ||
(index !== 1 &&
index % 2 !== 0 &&
index % 3 !== 0 &&
index % 5 !== 0 &&
index % 7 !== 0)) {
@krcrawford
krcrawford / time-adder.js
Created March 6, 2019 17:23
Javascript Homework #5
const timeAdder = (value1, label1, value2, label2) => {
if (typeof value1 !== "number" || typeof value2 !== "number") {
console.log("Values must be numbers");
return false; // must be numbers
}
if (/\./.test(value1) || /\./.test(value2)) {
console.log("Values must be integers");
return false; // must be integers
}
if (value1 < 0 || value2 < 0) {
@krcrawford
krcrawford / functions.js
Last active March 5, 2019 14:27
Javascript Homework #4
/**
* All men are mortal
* Socrates is a man.
* Therefore, socrates is mortal.
*/
const Man = function(name) {
this.name = name;
}
@krcrawford
krcrawford / statements-and-operators.js
Last active March 4, 2019 16:42
Javascript Homework #3
/**
* All men are mortal
* Socrates is a man.
* Therefore, socrates is mortal.
*/
const Man = function(name) {
this.name = name;
};