gr02 bookstore example
This commit is contained in:
parent
b31d0f3ab5
commit
e592c370d8
@ -22,10 +22,27 @@ var book3_title = "Why Grow Up?";
|
||||
var book3_price = 15.95;
|
||||
var book3_author = "Susan Neiman";
|
||||
|
||||
etc...
|
||||
|
||||
var book3 = {
|
||||
'title': "Why Grow Up?",
|
||||
'price': 15.95,
|
||||
'author': "Susan Neiman"
|
||||
};
|
||||
|
||||
|
||||
console.log(book3_price);
|
||||
|
||||
console.log(book3);
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
//etc...
|
||||
|
||||
|
||||
|
||||
// database of books
|
||||
var books = [
|
||||
{'title': "Ways of Curating",
|
||||
@ -66,28 +83,28 @@ program
|
||||
.parse(process.argv);
|
||||
|
||||
if(program.title) {
|
||||
for(let i = 0; i < books.length; i++) {
|
||||
for(var i = 0; i < books.length; i++) {
|
||||
if(program.title === books[i].title) {
|
||||
print_book(books[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(program.author) {
|
||||
for(let i = 0; i < books.length; i++) {
|
||||
for(var i = 0; i < books.length; i++) {
|
||||
if(program.author === books[i].author) {
|
||||
print_book(books[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(program.kind) {
|
||||
for(let i = 0; i < books.length; i++) {
|
||||
for(var i = 0; i < books.length; i++) {
|
||||
if(program.kind === books[i].kind) {
|
||||
print_book(books[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(program.max) {
|
||||
for(let i = 0; i < books.length; i++) {
|
||||
for(var i = 0; i < books.length; i++) {
|
||||
if(books[i].price < program.max) {
|
||||
print_book(books[i]);
|
||||
}
|
||||
|
||||
81
week2/gr02/gr02-bookstore/index.js
Normal file
81
week2/gr02/gr02-bookstore/index.js
Normal file
@ -0,0 +1,81 @@
|
||||
// import 'commander' (https://www.npmjs.com/package/commander)
|
||||
var program = require('commander');
|
||||
|
||||
/*
|
||||
var book1_title = "Ways of Curating";
|
||||
var book1_price = 16.95;
|
||||
var book1_author = "Hans Ulrich Orbist";
|
||||
|
||||
var book2_title = "Ardor";
|
||||
var book2_price = 39.5;
|
||||
var book2_author = "Roberto Calasso";
|
||||
|
||||
var book3_title = "Why Grow Up?";
|
||||
var book3_price = 15.95;
|
||||
var book3_author = "Susan Neiman";
|
||||
*/
|
||||
|
||||
var book1 = {
|
||||
'title': "Ways of Curating",
|
||||
'price': 16.95,
|
||||
'author': "Hans Ulrich Orbist"
|
||||
};
|
||||
|
||||
var book2 = {
|
||||
'title': "Ardor",
|
||||
'price': 39.5,
|
||||
'author': "Roberto Calasso"
|
||||
};
|
||||
|
||||
var book3 = {
|
||||
'title': "Why Grow Up?",
|
||||
'price': 15.95,
|
||||
'author': "Susan Neiman"
|
||||
};
|
||||
|
||||
var array_of_books = [
|
||||
{ 'title': "Ways of Curating",
|
||||
'price': 16.95,
|
||||
'author': "Hans Ulrich Orbist"
|
||||
},
|
||||
{ 'title': "Ardor",
|
||||
'price': 39.5,
|
||||
'author': "Roberto Calasso"
|
||||
},
|
||||
{'title': "Why Grow Up?",
|
||||
'price': 15.95,
|
||||
'author': "Susan Neiman"
|
||||
}
|
||||
];
|
||||
|
||||
function print_the_book(a_book) {
|
||||
console.log("----------");
|
||||
console.log("Title: " + a_book.title);
|
||||
console.log("Price: " + a_book.price);
|
||||
console.log("Author: " + a_book.author);
|
||||
}
|
||||
|
||||
// LOOP
|
||||
|
||||
for(var i = 0; i < array_of_books.length; i++) {
|
||||
print_the_book(array_of_books[i]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------
|
||||
|
||||
// old code
|
||||
|
||||
/*
|
||||
console.log(array_of_books[0]);
|
||||
console.log(array_of_books[1]);
|
||||
console.log(array_of_books[2]);
|
||||
*/
|
||||
|
||||
|
||||
//console.log(array_of_books.length);
|
||||
|
||||
//console.log(book3_price);
|
||||
|
||||
//console.log(book3);
|
||||
14
week2/gr02/gr02-bookstore/package.json
Normal file
14
week2/gr02/gr02-bookstore/package.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "gr01-bookstore",
|
||||
"version": "1.0.0",
|
||||
"description": "test code for week2 gr01",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "gauthier",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"commander": "^2.9.0"
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user