Skip to content

Instantly share code, notes, and snippets.

// get string as argument
function switchCharCode(str) {
// split string
str = str.split('');
str = str.map(function(char) {
let char_code;
if (char !== ' ') {
// convert each char to Unicode value and add three
char_code = char.charCodeAt(0);
@geopic
geopic / rng.js
Last active August 3, 2017 19:35
Random-number-generation function, useful for luck-based code
function findChoice() {
// local var generating random number, then console.log() to check it works
var rng = Math.floor(Math.random() * 100);
console.log(rng);
// function determining action to take depending on range of number generated
function choice() {
if (rng <= 10) {
console.log('Below or equal to 10');
} else if (rng > 10 && 20 >= rng) {
console.log('Above 10, up to 20');
@geopic
geopic / clock.js
Last active July 26, 2017 20:45
Simple auto-updating clock in Javascript
function displayClock() {
setInterval(function(){ document.getElementById('clock').innerHTML = new Date().toLocaleTimeString(); }, 1000);
};
displayClock();