var gamesText = `{
    "games":[
        {
            "name":"0hh1",
            "img":"img/0hh1.png",
            "path":"gfiles/0hh1/"
        },
        {
            "name":"0hn0",
            "img":"img/0hn0.png",
            "path":"gfiles/0hn0/"
        },
        {
            "name":"2048",
            "img":"img/2048.png",
            "path":"gfiles/2048/"
        },
        {
            "name":"Thirty Dollar Website",
            "img":"img/30dollarwebsite.jpg",
            "path":"gfiles/30dollarwebsite/"
        },
        {
            "name":"Alien Hominid",
            "img":"img/alienhominid.jpg",
            "path":"gfiles/alienhominid/"
        },
        {
            "name":"Amidst The Sky",
            "img":"img/amidstthesky.jpg",
            "path":"gfiles/amidstthesky/"
        },
        {
            "name":"Among Us",
            "img":"img/amongus.jpg",
            "path":"gfiles/among-us/"
        },
        {
            "name":"Animator vs Animation",
            "img":"img/animatorvsanimation.jpg",
            "path":"gfiles/animatorvsanimation/"
        },
        {
            "name":"Asteroids",
            "img":"img/asteroids.jpg",
            "path":"gfiles/asteroids/"
        },
        {
            "name":"Astray",
            "img":"img/astray.png",
            "path":"gfiles/astray/"
        },
        {
            "name":"Ballistic Chickens",
            "img":"img/ballistic-chickens.png",
            "path":"gfiles/ballistic-chickens/"
        },
        {
            "name":"Basket and Ball",
            "img":"img/basket-and-ball.jpg",
            "path":"gfiles/basketandball/"
        },
        {
            "name":"Basketbros.io",
            "img":"img/basketbros.jpg",
            "path":"gfiles/basketbros/"
        },
        {
            "name":"Bloons Tower Defense",
            "img":"img/btd.jpg",
            "path":"gfiles/btd/"
        },
        {
            "name":"Bloons Tower Defense 2",
            "img":"img/btd2.jpg",
            "path":"gfiles/btd2/"
        },
        {
            "name":"Bloons Tower Defense 3",
            "img":"img/btd3.jpg",
            "path":"gfiles/btd3/"
        },
        {
            "name":"Bloons Tower Defense 5",
            "img":"img/btd5.jpg",
            "path":"gfiles/btd5/"
        },
        {
            "name":"Blue",
            "img":"img/blue.png",
            "path":"gfiles/blue/"
        },
        {
            "name":"Cat Ninja",
            "img":"img/cat-ninja.jpg",
            "path":"gfiles/cat-ninja/"
        },
        {
            "name":"Champion Island",
            "img":"img/championisland.jpg",
            "path":"gfiles/champion-island/"
        },
        {
            "name":"Chess",
            "img":"img/chess.jpg",
            "path":"gfiles/chess/"
        },
        {
            "name":"Chill Radio",
            "img":"img/chillradio.jpg",
            "path":"gfiles/chill-radio/"
        },
        {
            "name":"Chrome Dinosaur Game",
            "img":"img/chromedino.jpg",
            "path":"gfiles/chrome-dino/"
        },
        {
            "name":"Circus Charlie",
            "img":"img/circus.jpg",
            "path":"gfiles/circus/"
        },
        {
            "name":"Clicker Heroes",
            "img":"img/clickerheroes.png",
            "path":"gfiles/clicker-heroes/"
        },
        {
            "name":"Cookie Clicker",
            "img":"img/cookieclicker.png",
            "path":"gfiles/cookieclicker/"
        },
        {
            "name":"CSGO Clicker",
            "img":"img/csgo.jpg",
            "path":"gfiles/csgo-clicker/"
        },
        {
            "name":"Cubefield",
            "img":"img/cubefield.jpg",
            "path":"gfiles/cubefield/"
        },
        {
            "name":"Custom Tetris",
            "img":"img/customtetris.jpg",
            "path":"gfiles/custom-tetris/"
        },
        {
            "name":"Dragon Ball Z Devolution",
            "img":"img/dbzdevolution.jpg",
            "path":"gfiles/dbzdevolution/"
        },
        {
            "name":"Doodle Jump",
            "img":"img/doodlejump.png",
            "path":"gfiles/doodle-jump/"
        },
        {
            "name":"DOOM",
            "img":"img/doom.jpg",
            "path":"gfiles/doom/"
        },
        {
            "name":"Drift Boss",
            "img":"img/driftboss.png",
            "path":"gfiles/drift-boss/"
        },
        {
            "name":"Eaglercraft 1.5.2",
            "img":"img/eaglercraft.png",
            "path":"gfiles/eaglercraft/"
        },
        {
            "name":"Eaglercraft 1.8.8",
            "img":"img/eaglerx.png",
            "path":"gfiles/eaglerx/"
        },
        {
            "name":"Edge Surf",
            "img":"img/edgesurf.png",
            "path":"gfiles/edgesurf/"
        },
        {
            "name":"Eggy Car",
            "img":"img/eggycar.png",
            "path":"gfiles/eggy-car/"
        },
        {
            "name":"Elastic Man",
            "img":"img/elasticman.jpg",
            "path":"gfiles/elastic-man/"
        },
        {
            "name":"Fancy Pants Adventure",
            "img":"img/fpa.jpg",
            "path":"gfiles/fancypants/"
        },
        {
            "name":"Flappy Bird",
            "img":"img/flappybird.png",
            "path":"gfiles/flappybird/"
        },
        {
            "name":"Fluid Simulation",
            "img":"img/fluidsimulation.png",
            "path":"gfiles/fluid-simulation/"
        },
        {
            "name":"Five Nights at Freddy's",
            "img":"img/fnaf.jpeg",
            "path":"gfiles/fnaf/"
        },
        {
            "name":"Five Nights at Winston's",
            "img":"img/fnaw.jpg",
            "path":"gfiles/fnaw/"
        },
        {
            "name":"Friday Night Funkin",
            "img":"img/fnf.jpg",
            "path":"gfiles/fnf-week7/"
        },
        {
            "name":"Funny Shooter 2",
            "img":"img/funnyshooter2.jpg",
            "path":"gfiles/funnyshooter2/"
        },
        {
            "name":"GBA Emulator",
            "img":"img/gba.jpg",
            "path":"gfiles/gba/"
        },
        {
            "name":"Google Snake",
            "img":"img/gsnake.png",
            "path":"gfiles/google-snake/"
        },
        {
            "name":"Hacker Typer",
            "img":"img/hackertyper.png",
            "path":"gfiles/hackertyper/"
        },
        {
            "name":"HexGL",
            "img":"img/hexgl.png",
            "path":"gfiles/hexgl/"
        },
        {
            "name":"Hextris",
            "img":"img/hextris.png",
            "path":"gfiles/hextris/"
        },
        {
            "name":"HTML Editor",
            "img":"img/htmledit.jpg",
            "path":"gfiles/html-editor/"
        },
        {
            "name":"Impossible Quiz",
            "img":"img/impossiblequiz.jpg",
            "path":"gfiles/impossible-quiz/"
        },
        {
            "name":"Incremancer",
            "img":"img/incremancer.png",
            "path":"gfiles/incremancer/"
        },
        {
            "name":"Jacksmith",
            "img":"img/jacksmith.png",
            "path":"gfiles/jacksmith/"
        },
        {
            "name":"Learn to Fly",
            "img":"img/ltf.png",
            "path":"gfiles/ltf/"
        },
        {
            "name":"Learn to Fly 2",
            "img":"img/ltf2.jpg",
            "path":"gfiles/ltf2/"
        },
        {
            "name":"Madalin Stunt Cars 2",
            "img":"img/madalincars2.jpg",
            "path":"gfiles/madalin-cars-2/"
        },
        {
            "name":"Minecraft Classic",
            "img":"img/classicminecraft.png",
            "path":"gfiles/mc-classic/"
        },
        {
            "name":"Minecraft Tower Defense",
            "img":"img/mctd.jpg",
            "path":"gfiles/mctd/"
        },
        {
            "name":"Minecraft Tower Defense 2",
            "img":"img/mctd2.jpg",
            "path":"gfiles/mctd2/"
        },
        {
            "name":"Mineblocks",
            "img":"img/mineblocks.png",
            "path":"gfiles/mineblocks/"
        },
        {
            "name":"Microsoft Flight Simulator",
            "img":"img/msflight.png",
            "path":"gfiles/msflight/"
        },
        {
            "name":"Minesweeper",
            "img":"img/minesweep.png",
            "path":"gfiles/minesweeper/"
        },
        {
            "name":"Moon Lander",
            "img":"img/moonlander.png",
            "path":"gfiles/moonlander/"
        },
        {
            "name":"Moto X3M",
            "img":"img/motox3m.png",
            "path":"gfiles/motox3m/"
        },
        {
            "name":"N64 Emulator",
            "img":"img/n64.jpg",
            "path":"gfiles/n64/"
        },
        {
            "name":"n-gon",
            "img":"img/n-gon.png",
            "path":"gfiles/n-gon/"
        },
        {
            "name":"OliCryptor",
            "img":"img/olicryptor.jpeg",
            "path":"gfiles/olicryptor/"
        },
        {
            "name":"Pac-Man",
            "img":"img/pacman.jpg",
            "path":"gfiles/pac-man/"
        },
        {
            "name":"Pac-Man 3D",
            "img":"img/pacman3d.jpeg",
            "path":"gfiles/pacman-3d/"
        },
        {
            "name":"Paper.io 2",
            "img":"img/paperio2.png",
            "path":"gfiles/paperio2/"
        },
        {
            "name":"PICO-8 Education",
            "img":"img/pico-8.png",
            "path":"gfiles/pico-8/"
        },
        {
            "name":"PiClient",
            "img":"img/eaglerx.png",
            "path":"gfiles/piclient/"
        },
        {
            "name":"POOM",
            "img":"img/poom.jpg",
            "path":"gfiles/poom/"
        },
        {
            "name":"Powder Game",
            "img":"img/powdergame.jpeg",
            "path":"gfiles/powder-game/dust2.html"
        },
        {
            "name":"RetroArch",
            "img":"img/webretro.png",
            "path":"gfiles/retroarch/"
        },
        {
            "name":"Retro Bowl",
            "img":"img/retrobowl.jpg",
            "path":"gfiles/retro-bowl/"
        },
        {
            "name":"Riddle School",
            "img":"img/riddleschool.png",
            "path":"gfiles/riddleschool/"
        },
        {
            "name":"Riddle School 2",
            "img":"img/riddleschool2.png",
            "path":"gfiles/riddleschool2/"
        },
        {
            "name":"Riddle School 3",
            "img":"img/riddleschool3.png",
            "path":"gfiles/riddleschool3/"
        },
        {
            "name":"Riddle School 4",
            "img":"img/riddleschool4.png",
            "path":"gfiles/riddleschool4/"
        },
        {
            "name":"Riddle School 5",
            "img":"img/riddleschool5.png",
            "path":"gfiles/riddleschool5/"
        },
        {
            "name":"Riddle Transfer",
            "img":"img/riddletransfer.png",
            "path":"gfiles/riddletransfer/"
        },
        {
            "name":"Riddle Transfer 2",
            "img":"img/riddletransfer2.png",
            "path":"gfiles/riddletransfer2/"
        },
        {
            "name":"Ruffle (Flash Emulator)",
            "img":"img/ruffle.png",
            "path":"gfiles/ruffle-demo/"
        },
        {
            "name":"Run 2",
            "img":"img/run2.png",
            "path":"gfiles/run2/"
        },
        {
            "name":"Sandboxels",
            "img":"img/sandboxels.png",
            "path":"gfiles/sandboxels/"
        },
        {
            "name":"Sandspiel",
            "img":"img/sandspiel.png",
            "path":"gfiles/sandspiel/"
        },
        {
            "name":"Strike Force Heroes",
            "img":"img/sfh.jpg",
            "path":"gfiles/sfh/"
        },
        {
            "name":"Strike Force Heroes 2",
            "img":"img/sfh2.png",
            "path":"gfiles/sfh2/"
        },
        {
            "name":"Strike Force Heroes 3",
            "img":"img/sfh3.png",
            "path":"gfiles/sfh3/"
        },
        {
            "name":"Slope",
            "img":"img/slope.jpg",
            "path":"gfiles/slope/"
        },
        {
            "name":"Super Mario 64",
            "img":"img/sm64.jpg",
            "path":"gfiles/sm64/"
        },
        {
            "name":"Space Cadet Pinball",
            "img":"img/spacecadetpinball.jpg",
            "path":"gfiles/space-cadet-pinball/"
        },
        {
            "name":"Spelunky",
            "img":"img/spelunky.jpg",
            "path":"gfiles/spelunky/"
        },
        {
            "name":"Spinning Rat",
            "img":"img/spinningrat.png",
            "path":"gfiles/spinningrat/"
        },
        {
            "name":"Subway Surfers",
            "img":"img/subwaysurfers.png",
            "path":"gfiles/subway-surfers/"
        },
        {
            "name":"Super Smash Flash",
            "img":"img/ssf.png",
            "path":"gfiles/ssf/"
        },
        {
            "name":"Tab Hider",
            "img":"img/tabhidder.png",
            "path":"gfiles/tab-hidder/"
        },
        {
            "name":"Tank Trouble 2",
            "img":"img/tanktrouble2.jpg",
            "path":"gfiles/tank-trouble-2/"
        },
        {
            "name":"Tanuki Sunset",
            "img":"img/tanuki.jpg",
            "path":"gfiles/tanuki-sunset/"
        },
        {
            "name":"Temple Run 2",
            "img":"img/templerun2.jpeg",
            "path":"gfiles/temple-run-2/"
        },
        {
            "name":"Tetris",
            "img":"img/tetris.jpg",
            "path":"gfiles/tetris/"
        },
        {
            "name":"Tiny Fishing",
            "img":"img/tiny-fishing.png",
            "path":"gfiles/tinyfishing/"
        },
        {
            "name":"Toss The Turtle",
            "img":"img/tosstheturtle.png",
            "path":"gfiles/tosstheturtle/"
        },
        {
            "name":"Overtype Typewriter",
            "img":"img/typewriter.jpeg",
            "path":"gfiles/typewriter/"
        },
        {
            "name":"Unfair Mario",
            "img":"img/unfairmario.jpg",
            "path":"gfiles/unfair-mario/"
        },
        {
            "name":"Very Normal Shooter",
            "img":"img/verynormalshooter.jpg",
            "path":"gfiles/verynormalshooter/"
        },
        {
            "name":"Vex 3",
            "img":"img/vex-3.jpg",
            "path":"gfiles/vex3/"
        },
        {
            "name":"Vex 4",
            "img":"img/vex4.jpg",
            "path":"gfiles/vex4/"
        },
        {
            "name":"Vex 5",
            "img":"img/vex-5.jpg",
            "path":"gfiles/vex5/"
        },
        {
            "name":"Vex 6",
            "img":"img/vex6.jpg",
            "path":"gfiles/vex6/"
        },
        {
          "name":"VM Linux",
          "img":"img/vmlinux.png",
          "path":"gfiles/vmlinux/"
        },
        {
            "name":"Wall Smash",
            "img":"img/wallsmash.png",
            "path":"gfiles/wallsmash/"
        },
        {
            "name":"Waterworks!",
            "img":"img/waterworks.png",
            "path":"gfiles/waterworks/"
        },
        {
            "name":"WBWWB",
            "img":"img/wbwwb.png",
            "path":"gfiles/wbwwb/"
        },
        {
            "name":"Weave Silk",
            "img":"img/weavesilk.jpg",
            "path":"gfiles/weavesilk/"
        },
        {
            "name":"Wordle",
            "img":"img/wordle.jpg",
            "path":"gfiles/wordle/"
        },
        {
            "name":"World's Hardest Game",
            "img":"img/hardestgame.jpg",
            "path":"gfiles/worlds-hardest-game/"
        }
    ]
}`;
var gameObject = JSON.parse(gamesText);
for (i in gameObject.games) {
  let elem1 = document.createElement("div");
  elem1.className = "game-button";
  document.getElementById("gameSelect").appendChild(elem1);
  console.log("div made");
  let elem2 = document.createElement("a");
  
    elem2.href = gameObject.games[i].path;
  
  elem1.appendChild(elem2);
  console.log("a made");
  let elem3 = document.createElement("img");
  elem3.src = gameObject.games[i].img;
  elem3.alt = gameObject.games[i].name;
  elem2.appendChild(elem3);
  console.log("img made");
  let elem4 = document.createElement("p");
  elem4.innerHTML = gameObject.games[i].name;
  elem2.appendChild(elem4);
  console.log("p made");
}
const gamesContainer = document.getElementById("gameSelect");
const searchBar = document.getElementById("search");
// Listen for input event on the search bar
searchBar.addEventListener('input', (e) => {
  const query = searchBar.value.trim().toLowerCase();

  // Loop through all the games in the container and show/hide them depending on whether they match the search query
  for (let game of gamesContainer.children) {
    if (game instanceof Element) {
      if (query) {
        const gameName = game.querySelector('p').innerText.trim().toLowerCase();
        if (gameName.includes(query)) {
          game.removeAttribute('hidden');
        } else {
          game.setAttribute('hidden', '');
        }
      } else {
        game.removeAttribute('hidden');
      }
    }
  }
}); 
by

Javascript Online Compiler

Write, Run & Share Javascript code online using OneCompiler's JS online compiler for free. It's one of the robust, feature-rich online compilers for Javascript language. Getting started with the OneCompiler's Javascript editor is easy and fast. The editor shows sample boilerplate code when you choose language as Javascript and start coding.

About Javascript

Javascript(JS) is a object-oriented programming language which adhere to ECMA Script Standards. Javascript is required to design the behaviour of the web pages.

Key Features

  • Open-source
  • Just-in-time compiled language
  • Embedded along with HTML and makes web pages alive
  • Originally named as LiveScript.
  • Executable in both browser and server which has Javascript engines like V8(chrome), SpiderMonkey(Firefox) etc.

Syntax help

STDIN Example

var readline = require('readline');
var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});

rl.on('line', function(line){
    console.log("Hello, " + line);
});

variable declaration

KeywordDescriptionScope
varVar is used to declare variables(old way of declaring variables)Function or global scope
letlet is also used to declare variables(new way)Global or block Scope
constconst is used to declare const values. Once the value is assigned, it can not be modifiedGlobal or block Scope

Backtick Strings

Interpolation

let greetings = `Hello ${name}`

Multi line Strings

const msg = `
hello
world!
`

Arrays

An array is a collection of items or values.

Syntax:

let arrayName = [value1, value2,..etc];
// or
let arrayName = new Array("value1","value2",..etc);

Example:

let mobiles = ["iPhone", "Samsung", "Pixel"];

// accessing an array
console.log(mobiles[0]);

// changing an array element
mobiles[3] = "Nokia";

Arrow functions

Arrow Functions helps developers to write code in concise way, it’s introduced in ES6.
Arrow functions can be written in multiple ways. Below are couple of ways to use arrow function but it can be written in many other ways as well.

Syntax:

() => expression

Example:

const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
const squaresOfEvenNumbers = numbers.filter(ele => ele % 2 == 0)
                                    .map(ele => ele ** 2);
console.log(squaresOfEvenNumbers);

De-structuring

Arrays

let [firstName, lastName] = ['Foo', 'Bar']

Objects

let {firstName, lastName} = {
  firstName: 'Foo',
  lastName: 'Bar'
}

rest(...) operator

 const {
    title,
    firstName,
    lastName,
    ...rest
  } = record;

Spread(...) operator

//Object spread
const post = {
  ...options,
  type: "new"
}
//array spread
const users = [
  ...adminUsers,
  ...normalUsers
]

Functions

function greetings({ name = 'Foo' } = {}) { //Defaulting name to Foo
  console.log(`Hello ${name}!`);
}
 
greet() // Hello Foo
greet({ name: 'Bar' }) // Hi Bar

Loops

1. If:

IF is used to execute a block of code based on a condition.

Syntax

if(condition){
    // code
}

2. If-Else:

Else part is used to execute the block of code when the condition fails.

Syntax

if(condition){
    // code
} else {
    // code
}

3. Switch:

Switch is used to replace nested If-Else statements.

Syntax

switch(condition){
    case 'value1' :
        //code
        [break;]
    case 'value2' :
        //code
        [break;]
    .......
    default :
        //code
        [break;]
}

4. For

For loop is used to iterate a set of statements based on a condition.

for(Initialization; Condition; Increment/decrement){  
//code  
} 

5. While

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while (condition) {  
  // code 
}  

6. Do-While

Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.

do {  
  // code 
} while (condition); 

Classes

ES6 introduced classes along with OOPS concepts in JS. Class is similar to a function which you can think like kind of template which will get called when ever you initialize class.

Syntax:

class className {
  constructor() { ... } //Mandatory Class method
  method1() { ... }
  method2() { ... }
  ...
}

Example:

class Mobile {
  constructor(model) {
    this.name = model;
  }
}

mbl = new Mobile("iPhone");