🐘👽 Checkpoint
./public/script.js:1954897/2956 ./server.js:1954897/2812
This commit is contained in:
1 parent
6646907e85
commit
e3ca0b8030
2 files changed
+33
-22
No files matched your search
+9
-9
@@ -1,12 +1,12 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
let prev = null
|
||||
'use strict'
|
||||
const wordBank = document.getElementById('wordBank')
|
||||
const input = document.getElementById('input')
|
||||
, input = document.getElementById('input')
|
||||
let prev = null
|
||||
|
||||
;[].forEach.call(
|
||||
document.querySelectorAll('[data-open]'),
|
||||
function (el) {
|
||||
function (el, i, arr) {
|
||||
el.addEventListener('click', function (e) {
|
||||
const iam = Array.from(document.body.children).filter(el => !el.hidden)[0];
|
||||
iam.hidden = true;
|
||||
@@ -16,23 +16,23 @@
|
||||
document.getElementById(this.dataset.open).hidden = false
|
||||
}
|
||||
prev = iam
|
||||
});
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
;[].forEach.call(
|
||||
document.querySelectorAll('[data-fire]'),
|
||||
function (el) {
|
||||
function (el, i, arr) {
|
||||
el.addEventListener('click', function (e) {
|
||||
document.dispatchEvent(new Event(this.dataset.fire))
|
||||
});
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
document.addEventListener('word', (e) => {
|
||||
// wordBank.innerHTML = ''
|
||||
wordBank.innerHTML = Math.random()
|
||||
});
|
||||
})
|
||||
|
||||
document.addEventListener('fs', (e) => {
|
||||
if (!screen.orientation.lock) return
|
||||
@@ -44,7 +44,7 @@
|
||||
document.exitFullscreen()
|
||||
})
|
||||
})
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
}());
|
||||
@@ -1,22 +1,33 @@
|
||||
// server.js
|
||||
// where your node app starts
|
||||
|
||||
// init project
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const palabras = require('./palabras.js')
|
||||
|
||||
// we've started you off with Express,
|
||||
// but feel free to use whatever libs or frameworks you'd like through `package.json`.
|
||||
|
||||
// http://expressjs.com/en/starter/static-files.html
|
||||
app.use(express.static('public'));
|
||||
|
||||
// http://expressjs.com/en/starter/basic-routing.html
|
||||
app.get('/', function(request, response) {
|
||||
response.sendFile(__dirname + '/views/index.html');
|
||||
app.get('/', function (req, res) {
|
||||
res.sendFile(__dirname + '/views/index.html');
|
||||
});
|
||||
app.get('/palabras.json', function (req, res) {
|
||||
res.json({
|
||||
words: getRandom(palabras, 10)
|
||||
})
|
||||
});
|
||||
|
||||
// listen for requests :)
|
||||
const listener = app.listen(process.env.PORT, function() {
|
||||
console.log('Your app is listening on port ' + listener.address().port);
|
||||
console.log('Your app is listening on port ' + listener.address().port);
|
||||
});
|
||||
|
||||
function getRandom(arr, n) {
|
||||
var result = new Array(n)
|
||||
, len = arr.length
|
||||
, taken = new Array(len)
|
||||
;
|
||||
if (n > len) {
|
||||
throw new RangeError("getRandom: more elements taken than available");
|
||||
} while (n--) {
|
||||
var x = Math.floor(Math.random() * len);
|
||||
result[n] = arr[x in taken ? taken[x] : x];
|
||||
taken[x] = --len in taken ? taken[len] : len;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Reference in new issue
Block a user