"without touching the module, implement it so that the user can interact with it"... I'm stumped.

I've built an inventory management app in the console, but it didn't use a module, so it's made it very confusing for me. Posting some of the code as it's too long.
var inventory = [];

function clone(obj) {
return JSON.parse(JSON.stringify(obj));
}

/**
* @typedef {Object} Product
* @property {string} name
* @property {int} count
*/

/**
*
* @returns {Array<Product>}
*/
function getInventory() {
return clone(inventory);
}

/**
* Gets a product by name
* @param {string} name
* @returns {Product}
*/
function getProduct(name) {
let product = inventory.find((p) => p.name == name);
if (product == null || product == undefined) {
throw new Error("Product does not exist");
}
return clone(product);
}

/**
* Add product with initial supply/count
* @param {string} productName
* @param {int} count
*/
function addProduct(productName, count) {
inventory.push({ name: productName, count });
}
var inventory = [];

function clone(obj) {
return JSON.parse(JSON.stringify(obj));
}

/**
* @typedef {Object} Product
* @property {string} name
* @property {int} count
*/

/**
*
* @returns {Array<Product>}
*/
function getInventory() {
return clone(inventory);
}

/**
* Gets a product by name
* @param {string} name
* @returns {Product}
*/
function getProduct(name) {
let product = inventory.find((p) => p.name == name);
if (product == null || product == undefined) {
throw new Error("Product does not exist");
}
return clone(product);
}

/**
* Add product with initial supply/count
* @param {string} productName
* @param {int} count
*/
function addProduct(productName, count) {
inventory.push({ name: productName, count });
}
App.js
var fs = require("fs");
const prompt = require("prompt-sync")({ sigint: true });

import {
getInventory,
addProduct,
getProduct,
modifyProductCount,
removeProduct,
} from "./inventoryManagement.js";
getInventory();

//Without touching a single line of code from step 1, implement this module in a console app that the user can interface with.

const addItem = () => {

}
var fs = require("fs");
const prompt = require("prompt-sync")({ sigint: true });

import {
getInventory,
addProduct,
getProduct,
modifyProductCount,
removeProduct,
} from "./inventoryManagement.js";
getInventory();

//Without touching a single line of code from step 1, implement this module in a console app that the user can interface with.

const addItem = () => {

}
5 Replies
Rägnar O'ock
Rägnar O'ock15mo ago
that first code block is not a module, it doesn't have any export or import statement... and I'm not sure what you want to do
CDL
CDLOP15mo ago
it's a snippet, sorry the entire thing is too long without nitro lol https://jsfiddle.net/vwaxoer6/ the entire thing is here I have to implement the module into a console app that the user can interact with, so add/remove/view products I've built one before but not with module importing..
//Add item to inventory
const addItem = () => {
let Item = prompt("Enter the name of the item you wish to add: ");
let Name = Item.toLowerCase();
let Quantity = parseInt(prompt("Now enter the quantity: "));
inventory.push({ Name, Quantity });
saveCurrentInventoryToFile();
console.log(`${Name} added succesfully!`);
};
//Add item to inventory
const addItem = () => {
let Item = prompt("Enter the name of the item you wish to add: ");
let Name = Item.toLowerCase();
let Quantity = parseInt(prompt("Now enter the quantity: "));
inventory.push({ Name, Quantity });
saveCurrentInventoryToFile();
console.log(`${Name} added succesfully!`);
};
Rägnar O'ock
Rägnar O'ock15mo ago
would that not work?
import * as ProductManagment from "./inventoryManagement.js";

window.productManagement = ProductManagement;
import * as ProductManagment from "./inventoryManagement.js";

window.productManagement = ProductManagement;
CDL
CDLOP15mo ago
believe so
CDL
CDLOP15mo ago
https://github.com/callum-laing/build-progression we did it! Next step is to add the UI to the code.... WHERE I GOT STUCK ORIGINALLY. anyway time to close, cheers!
GitHub
GitHub - callum-laing/build-progression: Multiple step layered prog...
Multiple step layered progression from console to UI - GitHub - callum-laing/build-progression: Multiple step layered progression from console to UI
Want results from more Discord servers?
Add your server