Skip to content

Commit 5e82356

Browse files
initial commit
0 parents  commit 5e82356

File tree

8 files changed

+4711
-0
lines changed

8 files changed

+4711
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

app.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const { generateText, createElement, validateInput } = require('./util');
2+
3+
const initApp = () => {
4+
// Initializes the app, registers the button click listener
5+
const newUserButton = document.querySelector('#btnAddUser');
6+
newUserButton.addEventListener('click', addUser);
7+
};
8+
9+
const addUser = () => {
10+
// Fetches the user input, creates a new HTML element based on it
11+
// and appends the element to the DOM
12+
const newUserNameInput = document.querySelector('input#name');
13+
const newUserAgeInput = document.querySelector('input#age');
14+
15+
if (
16+
!validateInput(newUserNameInput.value, true, false) ||
17+
!validateInput(newUserAgeInput.value, false, true)
18+
) {
19+
return;
20+
}
21+
22+
const userList = document.querySelector('.user-list');
23+
const outputText = generateText(
24+
newUserNameInput.value,
25+
newUserAgeInput.value
26+
);
27+
const element = createElement('li', outputText, 'user-item');
28+
userList.appendChild(element);
29+
};
30+
31+
// Start the app!
32+
initApp();

dist/main.js

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/******/ (function(modules) { // webpackBootstrap
2+
/******/ // The module cache
3+
/******/ var installedModules = {};
4+
/******/
5+
/******/ // The require function
6+
/******/ function __webpack_require__(moduleId) {
7+
/******/
8+
/******/ // Check if module is in cache
9+
/******/ if(installedModules[moduleId]) {
10+
/******/ return installedModules[moduleId].exports;
11+
/******/ }
12+
/******/ // Create a new module (and put it into the cache)
13+
/******/ var module = installedModules[moduleId] = {
14+
/******/ i: moduleId,
15+
/******/ l: false,
16+
/******/ exports: {}
17+
/******/ };
18+
/******/
19+
/******/ // Execute the module function
20+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
21+
/******/
22+
/******/ // Flag the module as loaded
23+
/******/ module.l = true;
24+
/******/
25+
/******/ // Return the exports of the module
26+
/******/ return module.exports;
27+
/******/ }
28+
/******/
29+
/******/
30+
/******/ // expose the modules object (__webpack_modules__)
31+
/******/ __webpack_require__.m = modules;
32+
/******/
33+
/******/ // expose the module cache
34+
/******/ __webpack_require__.c = installedModules;
35+
/******/
36+
/******/ // define getter function for harmony exports
37+
/******/ __webpack_require__.d = function(exports, name, getter) {
38+
/******/ if(!__webpack_require__.o(exports, name)) {
39+
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
40+
/******/ }
41+
/******/ };
42+
/******/
43+
/******/ // define __esModule on exports
44+
/******/ __webpack_require__.r = function(exports) {
45+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
46+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
47+
/******/ }
48+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
49+
/******/ };
50+
/******/
51+
/******/ // create a fake namespace object
52+
/******/ // mode & 1: value is a module id, require it
53+
/******/ // mode & 2: merge all properties of value into the ns
54+
/******/ // mode & 4: return value when already ns object
55+
/******/ // mode & 8|1: behave like require
56+
/******/ __webpack_require__.t = function(value, mode) {
57+
/******/ if(mode & 1) value = __webpack_require__(value);
58+
/******/ if(mode & 8) return value;
59+
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
60+
/******/ var ns = Object.create(null);
61+
/******/ __webpack_require__.r(ns);
62+
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
63+
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
64+
/******/ return ns;
65+
/******/ };
66+
/******/
67+
/******/ // getDefaultExport function for compatibility with non-harmony modules
68+
/******/ __webpack_require__.n = function(module) {
69+
/******/ var getter = module && module.__esModule ?
70+
/******/ function getDefault() { return module['default']; } :
71+
/******/ function getModuleExports() { return module; };
72+
/******/ __webpack_require__.d(getter, 'a', getter);
73+
/******/ return getter;
74+
/******/ };
75+
/******/
76+
/******/ // Object.prototype.hasOwnProperty.call
77+
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
78+
/******/
79+
/******/ // __webpack_public_path__
80+
/******/ __webpack_require__.p = "";
81+
/******/
82+
/******/
83+
/******/ // Load entry module and return exports
84+
/******/ return __webpack_require__(__webpack_require__.s = "./app.js");
85+
/******/ })
86+
/************************************************************************/
87+
/******/ ({
88+
89+
/***/ "./app.js":
90+
/*!****************!*\
91+
!*** ./app.js ***!
92+
\****************/
93+
/*! no static exports found */
94+
/***/ (function(module, exports, __webpack_require__) {
95+
96+
eval("const { generateText, createElement, validateInput } = __webpack_require__(/*! ./util */ \"./util.js\");\n\nconst initApp = () => {\n // Initializes the app, registers the button click listener\n const newUserButton = document.querySelector('#btnAddUser');\n newUserButton.addEventListener('click', addUser);\n};\n\nconst addUser = () => {\n // Fetches the user input, creates a new HTML element based on it\n // and appends the element to the DOM\n const newUserNameInput = document.querySelector('input#name');\n const newUserAgeInput = document.querySelector('input#age');\n\n if (\n !validateInput(newUserNameInput.value, true, false) ||\n !validateInput(newUserAgeInput.value, false, true)\n ) {\n return;\n }\n\n const userList = document.querySelector('.user-list');\n const outputText = generateText(\n newUserNameInput.value,\n newUserAgeInput.value\n );\n const element = createElement('li', outputText, 'user-item');\n userList.appendChild(element);\n};\n\n// Start the app!\ninitApp();\n\n\n//# sourceURL=webpack:///./app.js?");
97+
98+
/***/ }),
99+
100+
/***/ "./util.js":
101+
/*!*****************!*\
102+
!*** ./util.js ***!
103+
\*****************/
104+
/*! no static exports found */
105+
/***/ (function(module, exports) {
106+
107+
eval("exports.generateText = (name, age) => {\n // Returns output text\n return `${name} (${age} years old)`;\n};\n\nexports.createElement = (type, text, className) => {\n // Creates a new HTML element and returns it\n const newElement = document.createElement(type);\n newElement.classList.add(className);\n newElement.textContent = text;\n return newElement;\n};\n\nexports.validateInput = (text, notEmpty, isNumber) => {\n // Validate user input with two pre-defined rules\n if (!text) {\n return false;\n }\n if (notEmpty && text.trim().length === 0) {\n return false;\n }\n if (isNumber && +text === NaN) {\n return false;\n }\n return true;\n};\n\n\n//# sourceURL=webpack:///./util.js?");
108+
109+
/***/ })
110+
111+
/******/ });

index.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8+
<link rel="stylesheet" href="styles.css">
9+
<title>JS Testing</title>
10+
</head>
11+
12+
<body>
13+
<section class="control-panel">
14+
<div class="input-container">
15+
<label for="name">Name</label>
16+
<input type="text" id="name">
17+
</div>
18+
<div class="input-container">
19+
<label for="age">Age</label>
20+
<input type="number" id="age">
21+
</div>
22+
<button id="btnAddUser" class="button">Add User</button>
23+
</section>
24+
<hr>
25+
<section class="user-output">
26+
<ul class="user-list"></ul>
27+
</section>
28+
<script src="dist/main.js"></script>
29+
</body>
30+
31+
</html>

0 commit comments

Comments
 (0)