JSFiddle - React, Tailwind, and code Playground
by Newman5
HTML
<body id="body">
<form action="javascript:void(0);" id="exampleForm">
<input type="password" id="examplePass" />
<input type="submit" />
</form>
JavaScript
/// Interfacing to the DOM -Quiz Code for Udacity C255 HTML5 Game Dev
document.getElementById("exampleForm").onsubmit = function () {
var passwordRegex = /^[A-Za-z\d]{6,8}$/;
if (!passwordRegex.test(document.getElementById("examplePass").value)) {
console.log("regex didn't match");
var notify = document.getElementById("notify");
if (notify === null) {
notify = document.createElement("p");
notify.textContent = "Passwords are shitty. Make better."
notify.id = "notify";
var body = document.getElementById('body');
body.appendChild(notify);
}
}
};
setup = function () {
// Grab the body element using document.getElementById,
// assume the body element has an id of 'body'.
// Create a canvas element using document.createElement,
// then set the width and height properties to 1200 and
// 720, respectively.
// Finally, append the canvas element to the body.
var body = document.getElementById("body");
var canvas = document.createElement("canvas");
canvas.width = 1200;
canvas.height = 720;
body.appendChild(canvas);
};
setup();
document.write("Hello World!");
console.log("Dig dong")