JSFiddle - React, Tailwind, and code Playground

by DustyWhite

HTML

<div>
  Object Prototypes.
  <p>Open JavaScript Console to see results.</p>
</div>

JavaScript

"use strict";

// Array to hold Items
var items = [];

// Create Constructor Function for an Item Object
function Item(name, quantity, comment) {
	this.name = name;
	this.quantity = quantity;
	this.comment = comment;
}

// Create Prototype function
Item.prototype.getItemInfomration = function(){
	return this.name + ". Qty. " + this.quantity + ". " + this.comment;
}
  
// Create some Item Objects and put them in the Items Array
var item1 = new Item("Milk", 1, "Low Fat");
items.push(item1);

var item2 = new Item("Eggs", 12, "Large");
items.push(item2);

var item3 = new Item("Bread", 1, "Whole Grain");
items.push(item3);

// Display Items in Console
items.forEach(function(item) {
  // use Prototype to get Item Information
  console.log(item.getItemInfomration());
});