I’ve just started learning JavaScript, and i’m finding it very confusing so far. If anyone could help with any advice, many thanks in advance!
function Shoes (shoeName, productCode, quantity, itemValue) {
this.shoeName = shoeName;
this.productCode = productCode;
this.quantity = quantity;
this.itemValue = itemValue;
should ‘change’ and ‘shoeDescription’ be within the Shoe class, or separate functions? (as they are coming up in console.table)
this.change = function (name, code, qty, value) {
this.shoeName = name;
this.productCode = code;
this.quantity = qty;
this.itemValue = value;
console.log(`
Item:
${shoeName} ${productCode} ${quantity} ${itemValue}
has been edited to:
${name} ${code} ${qty} ${value}
`)
}
this.shoeDescription = function () {
return `
Shoe: ${this.shoeName}
Product Code: ${this.productCode}
Qty: ${this.quantity}
Value: ${this.itemValue}`
}
}
function shoeSearch(shoes01, shoes02){
let found = false;
shoes01.forEach(x => {
if(x.shoeName == shoes02){
console.log(`${shoes02} found.`);
found = true;
}
});
if(!found){
console.log(`${shoes02} not found.`)
}
}
function lowestItem(shoes01){
let low = shoes01[0].itemValue;
let shoeName = "";
shoes01.forEach(shoes02 => {
if (shoes02.itemValue < low){
low = shoes02.itemValue;
shoeName = shoes02.shoeName;
}
})
console.log(`${shoeName} is our cheapest item, with value of £${low}`)
}
function highestItem(shoes01){
let high = shoes01[0].itemValue;
let shoeName = "";
shoes01.forEach(shoes02 => {
if (shoes02.itemValue > high){
high = shoes02.itemValue;
shoeName = shoes02.shoeName;
}
})
console.log(`${shoeName} is our most expensive item has the value of £${high} `)
}
let sabat01 = new Shoes("nike", "nk0119", 2, 150);
let sabat02 = new Shoes("adidas", "ad5169", 43, 170);
let sabat03 = new Shoes("sketchers", "sk624", 10, 67);
let sabat04 = new Shoes("puma", "pu738", 20, 93);
let sabat05 = new Shoes("asics", "as823", 13, 50);
let shoeStock = [sabat01, sabat02, sabat03, sabat04, sabat05];
shoeStock.sort(
(p1, p2) =>
(p1.shoeName > p2.shoeName) ? 1 : (p1.shoeName < p2.shoeName) ? -1 : 0);
When i run these console.log, i don’t get why highest item doesn’t show
Also, how do i remove the ‘change’ and ‘shoe description’ from console.table
// find "adidas"
console.log(shoeSearch(shoeStock, "adidas"));
// try and find an item that doesnt exist
console.log(shoeSearch(shoeStock, "kicks"));
// find lowest item
console.log(lowestItem(shoeStock));
// find highest item
console.log(highestItem(shoeStock));
// get any item description
console.log(sabat03.shoeDescription());
// edit an item
console.log(sabat01.change("nike", "nk020", 88, 175));
// display product name in in ascending order
console.table (shoeStock)