Skip to content

Instantly share code, notes, and snippets.

View harrisonmalone's full-sized avatar

Harrison Malone harrisonmalone

View GitHub Profile
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script defer src="./index.js"></script>
</head>
<body>
<h1>Weather app 🌻</h1>
console.log(global);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script defer src="./index.js"></script>
</head>
<body>
<h1>Number of tasks: 0</h1>
// DOM
// special document variable
// object
// you can access it in client side js
// selector functions
// querySelector
// querySelectorAll
// const h1 = document.getElementsByTagName("h1")[0]
1. git
branches, commits, remotes
opening pull requests
code reviewed by someone
environments => prod, dev and staging
const readline = require("readline-sync")
const chalk = require("chalk")
const colors = ['red', 'blue', 'green', 'magenta']
console.log("hi, whats your name?")
const name = readline.question("> ")
console.log("whats your favorite color?")
const index = readline.keyInSelect(colors, 'Which color?');
// Promises
// Core:
// 1. What is fetch and how does it relate to AJAX? What does fetch return? Give a very basic example of fetch.
// AJAX is the terminology that encompasses all the different methods for making HTTP requests from our JavaScript. The two things we need for AJAX to work are: the XMLHTTPRequest() object, and JavaScript itself.
// The way in which fetch relates to AJAX is that fetch is a function makes an HTTP request and is therefore one way in which we can make AJAX requests.
const getUser = async () => {
const response = await fetch('https://randomuser.me/api/');
const data = await response.json();
return data
}
const getPokemon = async () => {
const response = await fetch('https://pokeapi.co/api/v2/pokemon');
const data = await response.json();
return data
<!DOCTYPE html>
<html>
<head> </head>
<body>
<button>Add student</button>
<script>
document.querySelector('button').addEventListener('click', function () {
let data = { student: { name: 'Sarah', location: 'Sydney' } }
fetch('http://localhost:3000/students', {
method: 'POST',
// Problem 1
// Write a function called arrayMultiply that takes two numbers, and a callback function as arguments. Return the callback function with the two numbers (those arguments) multiplied together as its argument.
// Define an array outside of this function. Because JS scope works differently to Ruby you will be able to use that array within the following function without passing it through as an argument. But please note that it will not be functional programming as such - but in this case if you use map a new array will be created (rather than the original being mutated).
// Define a variable and in it store the result of arrayMultiply when called with 2, 2, and also an anonymous callback function that takes the result as an argument, and then multiplies each element in the array by that result. When you console.log this variable to screen it should produce [ 4, 8, 12 ].
const arr = [1, 2, 3]
function arrayMultiply(num1, num2, cb) {
const sum = num1 * num2
// => 2 * 2 = 4