Skip to content

exercise list-items done #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const LIST_THINGS = 'list-things';
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
import { list } from './utils.js';
import { list } from './util.js';

export const listHandler = () => {
// read & process user input
const allInputs = [];
let acceptingInput = true;
while (acceptingInput) {
const nextInput = prompt('enter a list item, cancel when your are done');
if (nextInput !== null) {
allInputs.push(nextInput);
} else {
acceptingInput = false;
}
}

const stringList = list(allInputs);

// communicate result to user
const message = `all items:${stringList}`;
alert(message);
}

export const listHandler = () => {};
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
document.getElementById('list-things').addEventListener('click', () => {
import { LIST_THINGS } from "../data/constants";
import './listener';

/*document.getElementById(LIST_THINGS).addEventListener('click', () => {
// read & process user input
const allInputs = [];
let acceptingInput = true;
Expand All @@ -20,4 +23,4 @@ document.getElementById('list-things').addEventListener('click', () => {
// communicate result to user
const message = `all items:${stringList}`;
alert(message);
});
});*/
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
import { listHandler } from './handler.js';

document.getElementById('list-things').addEventListener('click', listHandler);
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
/**
*
*/
export const list = () => {};
export const list = (allInputs) => {
let stringList = '';
for (const input of allInputs) {
stringList += `\n- ${input}`;
}
return stringList;
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { list } from './utils.js';
import { list } from './util.js';

describe('list: generates a list string from an array of strings', () => {
describe('list: correctly lists items', () => {
Expand Down