Skip to content

Instantly share code, notes, and snippets.

// Tuples - Special Arrays with fixed type elements
const universe: [number, string] = [1, "Marvel"];
// Enum type
enum Seasons { SUMMER, WINTER, SPRING, AUTUMN };
// can be accessed as
//This function takes two string types as input and returns a string output
function greeting(firstName: string, lastName: string): string {
return firstName + lastName
}
let fullName = greeting("Han", "Solo")
console.log(fullName)
let message: string = "Hello World"; // string type variable
let myNum: number = 42; // number type variable
let isReal: boolean = true; // boolean type variable
let special: any = "Any type"; // any type variable
special = 13; // any type doesn't cause any type checking errors
<!-- Pull in P5.JS graphics library -->
<script
src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.1.9/p5.min.js"
integrity="sha512-WIklPM6qPCIp6d3fSSr90j+1unQHUOoWDS4sdTiR8gxUTnyZ8S2Mr8e10sKKJ/bhJgpAa/qG068RDkg6fIlNFA=="
crossorigin="anonymous"
></script>
<script>
const screenDim = 500;
let score = [0, 0];
let ball = { x: 250, y: 100, vx: 2, vy: 2 };
<!-- Pull in P5.JS graphics library -->
<script
src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.1.9/p5.min.js"
integrity="sha512-WIklPM6qPCIp6d3fSSr90j+1unQHUOoWDS4sdTiR8gxUTnyZ8S2Mr8e10sKKJ/bhJgpAa/qG068RDkg6fIlNFA=="
crossorigin="anonymous"
></script>
<script>
const screenDim = 500;
let ball = { x: 250, y: 100, vx: 2, vy: 2 };
<!-- Pull in P5.JS graphics library -->
<script
src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.1.9/p5.min.js"
integrity="sha512-WIklPM6qPCIp6d3fSSr90j+1unQHUOoWDS4sdTiR8gxUTnyZ8S2Mr8e10sKKJ/bhJgpAa/qG068RDkg6fIlNFA=="
crossorigin="anonymous"
></script>
<script>
const screenDim = 500;
let play1 = { x: 30, y: 250, height: 100, width: 20 };
let play2 = { x: screenDim - 50, y: 250, height: 100, width: 20 };
<!-- Pull in P5.JS graphics library -->
<script
src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.1.9/p5.min.js"
integrity="sha512-WIklPM6qPCIp6d3fSSr90j+1unQHUOoWDS4sdTiR8gxUTnyZ8S2Mr8e10sKKJ/bhJgpAa/qG068RDkg6fIlNFA=="
crossorigin="anonymous"
></script>
<script>
const screenDim = 500;
function setup() { // Runs on startup
frameRate(100);
<!DOCTYPE html>
<html>
<head>
<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
</head>
<body>
<a-scene>
<a-sphere id = "ball" position="0 1.25 -5" radius="1.25" color="#EF2D5E"></a-sphere>
<a-plane position="0 0 -4" rotation="-90 0 0" width="4" height="4" color="#7BC8A4"></a-plane>
<a-sky color="#ECECEC"></a-sky>
const http = require('http')
const fs = require('fs')
const server = http.createServer((req, res) => {
res.writeHead(200, { 'content-type': 'text/html' })
fs.createReadStream('PUT THE NAME OF YOUR HTML FILE HERE').pipe(res)
})
server.listen(process.env.PORT || 3000)
<!DOCTYPE html>
<html>
<head>
<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
</head>
<body>
<a-scene>
<a-sphere id = "ball" position="0 1.25 -5" radius="1.25" color="#EF2D5E"></a-sphere>
<a-plane position="0 0 -4" rotation="-90 0 0" width="4" height="4" color="#7BC8A4"></a-plane>
<a-sky color="#ECECEC"></a-sky>