The variables following are defined through a Car prototype:
var Car = function(maker, type, model) {
this.maker = maker;
this.type = type;
this.model = model;
}
var golf = new Car('VW', 'Hatchback', 'Golf');
var sentra = new Car('Nissan', 'Sedan', 'Sentra');
var _328i = new Car('BMW', 'Convertible', "328i");
var gallardo = new Car('Lamborghini', 'Convertible', "Gallardo");
var corniche = new Car('Rolls Royce', 'Sedan', "Corniche");
Car.prototype.year = 0;
golf.year = 2015;
sentra.year = 2010;
_328i.year = 2019;
gallardo.year = 2020;
corniche.year = 1998;
How does one build an array of the var values for the property maker
Something that might console log like this:
(5) ['VW', 'Nissan', 'BMW', 'Lamborghini', 'Roll Royce']
You could create an array of the car instances and use the map function
console.log(
[golf, sentra, _328i, gallardo, corniche].map((car) => car.maker)
)
There are a lot of solutions to that. First, you need to make an array with all your cars, and then use a method to iterate on each car to get the car maker.
Here two examples:
var Car = function (maker, type, model) {
this.maker = maker;
this.type = type;
this.model = model;
}
Car.prototype.year = 0;
var golf = new Car ('VW', 'Hatchback', 'Golf');
var sentra = new Car ('Nissan', 'Sedan', 'Sentra');
var _328i = new Car ('BMW', 'Convertible', "328i");
var gallardo = new Car ('Lamborghini', 'Convertible', "Gallardo", 2020);
var corniche = new Car('Rolls Royce', 'Sedan', "Corniche");
golf.year = 2015;
sentra.year = 2010;
_328i.year = 2019;
gallardo.year = 2020;
corniche.year = 1998;
var cars = [golf, sentra, _328i, gallardo, corniche]
var carsMakers = []
for(var i = 0; i < cars.length; i++) {
var c = cars[i]
carsMakers.push(c.maker)
}
console.log(carsMakers)
var carsMakers2 = cars.map(function(c) { return c.maker });
console.log(carsMakers2)
Just like the map approach but using Array.prototype.from:
var Car = function (maker, type, model) {
this.maker = maker;
this.type = type;
this.model = model;
}
var golf = new Car ('VW', 'Hatchback', 'Golf');
var sentra = new Car ('Nissan', 'Sedan', 'Sentra');
var _328i = new Car ('BMW', 'Convertible', "328i");
var gallardo = new Car ('Lamborghini', 'Convertible', "Gallardo");
var corniche = new Car('Rolls Royce', 'Sedan', "Corniche");
Car.prototype.year = 0;
golf.year = 2015;
sentra.year = 2010;
_328i.year = 2019;
gallardo.year = 2020;
corniche.year = 1998;
// Solution here
const makersList = Array.from([golf, sentra, _328i, gallardo, corniche], car => car.maker );
// should print an array of makers string names
console.log(makersList);
Related
I have a snippet of code that compares two dates and if they're the same it sets a boolean to true. I am getting an error on the line: var nextFolioArrive = new Date(this.folios[i+1].folioDepart);
TypeError: Cannot read property "folioDepart" from undefined. (line 50, file "propertyObject")
However it throws no error when I define:
var folioDepart = new Date(this.folios[i].folioDepart);
I was wondering if I can't "look ahead" in an array like that, not sure why it would be an issue.
property.prototype.isTurn = function(){
for (var i=0;i<this.folios.length;i++){
var folioArrive = new Date(this.folios[i].folioArrive);
var folioDepart = new Date(this.folios[i].folioDepart);
var nextFolioArrive = new Date(this.folios[i+1].folioDepart);
if(folioDepart == nextFolioArrive && folioArrive == TODAY){
Logger.log("turn day: " +this.turnDay);
return this.turnDay = true;
}
Logger.log("turn day: false" );
}
}
Here is all the code in the property object, I feel like I am making a silly syntax mistake or over looking something small.
var TODAY = new Date();
TODAY.setHours(0,0,0,0)
var propertyList = new Array();
function property(name,address) {
//Default variables
//Object variables
this.name = name;
this.address = address;
this.workOrders = new Array();
this.folios = new Array();
this.GIH = false;
this.turnDay = false;
propertyList.push(this);
property.prototype.listArrivals = function(){
Logger.log(this.name);
for(var i=0;i<this.folios.length;i++){
Logger.log(this.folios[i].folioID);
}
}
property.prototype.listWorkorders = function(){
Logger.log(this.name);
for(var i=0;i<this.workOrders.length;i++){
Logger.log(this.workOrders[i].workorderID);
}
}
property.prototype.getGIH = function(){
for (var i = 0;i<this.folios.length;i++){
var folioArrive = new Date(this.folios[i].folioArrive);
var folioDepart = new Date(this.folios[i].folioDepart);
if(TODAY >= folioArrive && TODAY <= folioDepart && this.GIH == false){
return this.GIH = true;
}
}
}
property.prototype.isTurn = function(){
for (var i=0;i<this.folios.length;i++){
var folioArrive = new Date(this.folios[i].folioArrive);
var folioDepart = new Date(this.folios[i].folioDepart);
var k = i+1;
var nextFolioArrive = new Date(this.folios[k].folioDepart);
if(folioDepart == nextFolioArrive && folioArrive == TODAY){
Logger.log("turn day: " +this.turnDay);
return this.turnDay = true;
}
Logger.log("turn day: false" );
}
}
}
I should have included my testing environment.
function myFunction() {
function addDays(date, days) {
var result = new Date(date);
result.setDate(result.getDate() + days);
return result;
}
var tempPropertyList = [];
var tempWorkOrderList = [];
var tempFolioList = [];
var i;
var j;
var k;
var property1 = new property("property1","123 street");
var property2 = new property("property2","123 ave");
// folio(ID,type,propName,address,arrive,depart)
var folio1 = new folio("303245","type","property1","123 street","03/14/2019", "03/30/2019");
var folio2 = new folio("303243","type","property2","123 ave","03/26/2019", "03/30/2019");
var folio3 = new folio("303244","type","property1","123 street","03/30/2019", "04/10/2019");
var folio4 = new folio("303246","type","property2","123 ave","03/20/2019", "03/25/2019");
var folio5 = new folio("303247","type","property1","123 street","03/01/2019", "03/14/2019");
//workOrder(ID,propName,type,description,due,notes) {
var wo1 = new workOrder("12","property1","Maint","workOrder1","03/14/2019","");
var wo2 = new workOrder("13","property2","Maint","workOrder2","03/20/2019","");
var wo3 = new workOrder("14","property1","Maint","workOrder3","03/19/2019","");
var wo4 = new workOrder("15","property1","Maint","workOrder4","02/02/2019","");
var wo5 = new workOrder("16","property2","Maint","workOrder5","03/14/2019","");
var wo6 = new workOrder("17","property2","Maint","workOrder6","03/14/2019","");
var wo7 = new workOrder("18","property1","Maint","workOrder7","03/15/2019","");
var wo8 = new workOrder("19","property1","Maint","workOrder8","03/16/2019","");
var wo9 = new workOrder("10","property2","Maint","workOrder9","04/01/2019","");
var wo10 = new workOrder("11","property2","Maint","workOrder10","05/05/2019","");
//push objects to arrays
tempWorkOrderList.push(wo1,wo2,wo3,wo4,wo5,wo6,wo7,wo8,wo9,wo10);
tempFolioList.push(folio1,folio5,folio2,folio3,folio4);
tempPropertyList.push(property1,property2);
for (i=0;i<tempPropertyList.length;i++){
tempPropertyList[i].isTurn();
for (j=0;j<tempWorkOrderList.length;j++){
if (tempWorkOrderList[j].workorderProperty == tempPropertyList[i].name){
tempPropertyList[i].workOrders.push(tempWorkOrderList[j]);
}
}
for (k=0;k<tempFolioList.length;k++){
if(tempFolioList[k].folioProperty == tempPropertyList[i].name){
tempPropertyList[i].folios.push(tempFolioList[k]);
}
}
tempPropertyList[i].isTurn();
}
}
Check the existance of the object first before using its property
property.prototype.isTurn = function(){
for (var i=0;i<this.folios.length;i++){
var folioArrive = new Date(this.folios[i].folioArrive);
var folioDepart = new Date(this.folios[i].folioDepart);
// check next folio
if (typeof this.folios[i+1] != 'undefined') {
var nextFolioArrive = new Date(this.folios[i+1].folioDepart);
if(folioDepart == nextFolioArrive && folioArrive == TODAY){
Logger.log("turn day: " +this.turnDay);
return this.turnDay = true;
}
Logger.log("turn day: false" );
}
}
}
I have data by date like this there is no 2017/07/17,2017/07/16,2017/07/15
because they are bank holidays.
chartData = new Array();
chartData[0] = new Array();
chartData[0].closePrice = 1207;
chartData[0].date = new Date("2017/07/12");
chartData[1] = new Array();
chartData[1].closePrice = 1227;
chartData[1].date = new Date("2017/07/13");
chartData[2] = new Array();
chartData[2].closePrice = 1216;
chartData[2].date = new Date("2017/07/14");
chartData[3] = new Array();
chartData[3].closePrice = 1234;
chartData[3].date = new Date("2017/07/18");
I use this chartData as dataProvider for making graph.
var dataSet = new AmCharts.DataSet();
dataSet.dataProvider = chartData;
dataSet.categoryField = "date";
chart.dataSets = [dataSet];
var stockPanel = new AmCharts.StockPanel();
stockPanel.title = "Stock Main";
stockPanel.id = "stockPanel";
stockPanel.showCategoryAxis = false;
stockPanel.recalculateToPercents = "never";
var valueAxis = new AmCharts.ValueAxis();
valueAxis.dashLength = 5;
stockPanel.addValueAxis(valueAxis);
stockPanel.categoryAxis.dashLength = 5;
stockPanel.categoryAxis.equalSpacing = true; // it doesn't work ....
var graph = new AmCharts.StockGraph();
graph.type = "line";
graph.valueField = "closePrice";
stockPanel.addStockGraph(graph);
however 2017/07/15,2017/07/16 2017/07/16 are drawn on X axis , even there are no data.
Even .equalSpacing looks in vain.
How can I remove this???
You have to set equalSpacing in the categoryAxesSettings property in the stock chart for it to work.
//object-based setup
chart.categoryAxesSettings = new AmCharts.CategoryAxesSettings();
chart.categoryAxesSettings.equalSpacing = true;
//makeChart version
AmCharts.makeChart("chartdiv", {
// ...
"categoryAxesSettings": {
"equalSpacing": true
},
// ...
});
Demo
I'm trying to fill an array with new objects, but the only thing I get is - Uncaught TypeError: product is not a constructor
Here's my code for obj. constructor:
function product(id, preview, colors, sizes, title, price) {
this.id = id;
this.preview = preview;
this.colors = colors;
this.sizes = sizes;
this.title = title;
this.price = price;
};
and code for loop:
var products = [];
for( i=0; i<db.length; i++) {
var xyz = db[i];
products[i] = new product( xyz.id, xyz.preview, xyz.colors, xyz.sizes, xyz.title, xyz.price );
};
here's "minfied" code block example:
https://jsfiddle.net/cujrfhyL/1/
-Thanks in advance.
If products array variable already has some kind of data, it's better you use the array push as not to override the data it contains
var product1 = { id: 6566, price: 3 };
var product2 = { id: 6566, price: 3 };
var product3 = { id: 6568, price: 3 };
var db = [ product1, product2 ];
function product(id, price) {
this.id = id;
this.price = price;
};
var products = [new product(product3.id,product3.price)];
function addProducts() {
for( i=0; i<db.length; i++) {
var xyz = db[i];
products.push(new product( xyz.id, xyz.price ));
}
console.log(products)
};
addProducts();
You need to use the new operator.
products[i] = new product( xyz.id, xyz.price );
var product1 = { id: 6566, price: 3 };
var product2 = { id: 6566, price: 3 };
var db = [ product1, product2 ];
function product(id, price) {
this.id = id;
this.price = price;
};
var products = [];
function addProducts() {
for( i=0; i<db.length; i++) {
var xyz = db[i];
products[i] = new product( xyz.id, xyz.price );
alert(products[i]);
}
};
addProducts();
Don't know if you are having your same problem on local, but in your fiddle you misstyped:
Written there:
var product1 = { id: 6566, price: 3 };
var product2 = { id: 6566, price: 3 };
var db = [ product6566, product6646 ];
But you need to reference product1 and product2 in db:
var db = [ product1, product2 ];
Appart from that, you need to use the "new" keyword:
your code:
products[i] = product( xyz.id, xyz.price );
Correct code:
products[i] = new product( xyz.id, xyz.price );
In Updated working fiddle you can see it working perfectly
I have got a pretty complicated issue, I tried everything and its not working properly. So the conception is (i just copied the interesting part of it, otherwise it would be few hundred more lines) :
The program is a card game and 24 cards (4 different colors, one is always stronger,it is called ADU) are distributed randomly among 4 players (4 arrays). The table where you put down the cards are represented by "asztal" array. First the human player puts a card, then the computers should reach in this order:
If they have same color and higher value - pick that card
If they have same color and any value - pick that card
If they dont have matching color, any car from the special color set (for being simple, its the first card the loop would find in the array)
If they dont have matching color, nor card from special color set, than the first element of the array (player[0]).
If you run my code, you would see it is not grabbing 1/1/1 card from each array, but sometimes more. And those cards do disappear, and not getting into the asztal array. My code: (https://jsfiddle.net/daxa3pL2/)
function CardA(name,value,adu){
this.name = name;
this.value = value;
};
function CardB(name,value,adu){
this.name = name;
this.value = value;
};
function CardC(name,value,adu){
this.name = name;
this.value = value;
};
function CardD(name,value,adu){
this.name = name;
this.value = value;
};
CardA.prototype.adu = false;
CardB.prototype.adu = false;
CardC.prototype.adu = false;
CardD.prototype.adu = false;
var a9 = new CardA("Tök kilenc",0);
var a10 = new CardA("Tök tíz",10);
var aal = new CardA("Tök alsó",2);
var afel = new CardA("Tök felső",3);
var akir = new CardA("Tök király",4);
var aasz = new CardA("Tök ász",11);
var b9 = new CardB("Levél kilenc",0);
var b10 = new CardB("Levél tíz",10);
var bal = new CardB("Levél alsó",2);
var bfel = new CardB("Levél felső",3);
var bkir = new CardB("Levél király",4);
var basz = new CardB("Levél ász",11);
var c9 = new CardC("Makk kilenc",0);
var c10 = new CardC("Makk tíz",10);
var cal = new CardC("Makk alsó",2);
var cfel = new CardC("Makk felső",3);
var ckir = new CardC("Makk király",4);
var casz = new CardC("Makk ász",11);
var d9 = new CardD("Szív kilenc",0);
var d10 = new CardD("Szív tíz",10);
var dal = new CardD("Szív alsó",2);
var dfel = new CardD("Szív felső",3);
var dkir = new CardD("Szív király",4);
var dasz = new CardD("Szív ász",11);
CardC.prototype.adu = true;
var player1 = [c9,b9,b10,d9,a9,d10];
var player2 = [a10,aal,dal,c10,cal,bal];
var player3 = [bfel,bkir,basz,dfel,dkir,dasz];
var player4 = [afel,akir,aasz,cfel,ckir,casz];
var asztal = [];
asztal.push(player1.splice(0,1)[0]);
var player2card1 = function() {
for (i = 0; i < player2.length; i++) {
if (Object.getPrototypeOf(player2[i]) == Object.getPrototypeOf(asztal[0]) && player2[i].value > asztal[0].value) {
asztal.push(player2.splice(i,i+1)[0])
return
}
}
if (asztal.length == 1) {
for (i = 0; i < player2.length; i++) {
if (Object.getPrototypeOf(player2[i]) == Object.getPrototypeOf(asztal[0])) {
asztal.push(player2.splice(i,i+1)[0])
return
}
}
}
if (asztal.length == 1){
for (i = 0; i < player2.length; i++) {
if (player2[i].adu == true) {
asztal.push(player2.splice(i,i+1)[0])
return
}
}
}
if (asztal.length == 1) {
asztal.push(player2.splice(0,1)[0])
return
}
};
var player3card1 = function() {
for (i = 0; i < player3.length; i++) {
if (Object.getPrototypeOf(player3[i]) == Object.getPrototypeOf(asztal[0]) && player3[i].value > asztal[0].value) {
asztal.push(player3.splice(i,i+1)[0])
return
}
}
if (asztal.length == 2) {
for (i = 0; i < player3.length; i++) {
if (Object.getPrototypeOf(player3[i]) == Object.getPrototypeOf(asztal[0])) {
asztal.push(player3.splice(i,i+1)[0])
return
}
}
}
if (asztal.length == 2){
for (i = 0; i < player3.length; i++) {
if (player3[i].adu == true) {
asztal.push(player3.splice(i,i+1)[0])
return
}
}
}
if (asztal.length == 2) {
asztal.push(player3.splice(0,1)[0])
return
}
};
var player4card1 = function() {
for (i = 0; i < player4.length; i++) {
if (Object.getPrototypeOf(player4[i]) == Object.getPrototypeOf(asztal[0]) && player4[i].value > asztal[0].value) {
asztal.push(player4.splice(i,i+1)[0])
return
}
}
if (asztal.length == 3) {
for (i = 0; i < player4.length; i++) {
if (Object.getPrototypeOf(player4[i]) == Object.getPrototypeOf(asztal[0])) {
asztal.push(player4.splice(i,i+1)[0])
return
}
}
}
if (asztal.length == 3){
for (i = 0; i < player4.length; i++) {
if (player4[i].adu == true) {
asztal.push(player4.splice(i,i+1)[0])
return
}
}
}
if (asztal.length == 3) {
asztal.push(player4.splice(0,1)[0])
return
}
};
player2card1();
player3card1();
player4card1();
console.log(player1);
console.log(player2);
console.log(player3);
console.log(player4);
console.log(asztal);
So I debugged your code and there are two fundamental mistakes I found:
1: When you use the splice inside a loop, the indices will change. So, when you do for example
asztal.push(player2.splice(i,i+1)[0])
and put it inside a loop, the indices for player2 matching your condition will change as soon as you do the splice. So the next iteration of your loop will give incorrect results/ miss an index of an object that should be removed.
A possible solution to this is that instead of splice, inside your for-loops, just insert elements into asztal, and DON'T splice the parent. Then outside the loop, splice them from from the players using a FILTER function as follows:
var player2card1 = function() {
for (i = 0; i < player2.length; i++) {
if (Object.getPrototypeOf(player2[i]) == Object.getPrototypeOf(asztal[0]) && player2[i].value > asztal[0].value) {
asztal.push({name: player2[i].name, value: player2[i].value, prototype: player2[i].prototype});
player2[i].name = "delete";
return
}
}
player2.filter((each)=>{return each.name!== "delete"});
2: The second mistake (that I don't think is the problem here but still can cause trouble) is your use of "==". In Javascript, try to use '===' as far as possible as it also checks the type along with equality.
A little refactoring can go a long way to making this clear.
// define a card type class
function CardType(type, adu)
{
// This simply says that if ADU is undefined (not passed) then
// ADU should be set to false by default
this.adu = (typeof adu === 'undefined' ? false : adu);
this.type = type;
}
function Card(name, value, type)
{
this.name = name;
this.value = value;
this.type = type;
}
// Define our card types
var CardA = new CardType("A");
var CardB = new CardType("B");
var CardC = new CardType("C", true);// set to be ADU
var CardD = new CardType("D");
// Define our cards
var a9 = new Card("Tök kilenc",0, CardA);
var a10 = new Card("Tök tíz",10, CardA);
var aal = new Card("Tök alsó",2, CardA);
var afel = new Card("Tök felső",3, CardA);
var akir = new Card("Tök király",4, CardA);
var aasz = new Card("Tök ász",11, CardA);
var b9 = new Card("Levél kilenc",0, CardB);
var b10 = new Card("Levél tíz",10, CardB);
var bal = new Card("Levél alsó",2, CardB);
var bfel = new Card("Levél felső",3, CardB);
var bkir = new Card("Levél király",4, CardB);
var basz = new Card("Levél ász",11, CardB);
var c9 = new Card("Makk kilenc",0, CardC);
var c10 = new Card("Makk tíz",10, CardC);
var cal = new Card("Makk alsó",2, CardC);
var cfel = new Card("Makk felső",3, CardC);
var ckir = new Card("Makk király",4, CardC);
var casz = new Card("Makk ász",11, CardC);
var d9 = new Card("Szív kilenc",0, CardD);
var d10 = new Card("Szív tíz",10, CardD);
var dal = new Card("Szív alsó",2, CardD);
var dfel = new Card("Szív felső",3, CardD);
var dkir = new Card("Szív király",4, CardD);
var dasz = new Card("Szív ász",11, CardD);
var player1 = [c9,b9,b10,d9,a9,d10];
var player2 = [a10,aal,dal,c10,cal,bal];
var player3 = [bfel,bkir,basz,dfel,dkir,dasz];
var player4 = [afel,akir,aasz,cfel,ckir,casz];
var asztal = [];
// It doesn't really make sense to splice the array because
// you are changing the array.
// asztal.push(player1.splice(0,1)[0]);
// This line can be replaced with a simple:
asztal.push(player1[0]);
// This function has lots of redundant code and we can simplify it greatly
// as well as generalize it to work for each player
function getNextCard(player, card){
// By default we take the first card unless we find a better one along the way.
var matchCase2 = null, // same type, any value
matchCase3 = null, // special set
matchCase4 = player[0]; // any card
for(i = 0; i < player.length; i++)
{
// Check our first case
if(player[i].type.type == card.type.type &&
player[i].value > card.value){
return player[i];
}
if(matchCase2 === null && player[i].type.type == card.type.type){
matchCase2 = player[i];
}
if(matchCase3 === null && player[i].type.adu === true){
matchCase3 = player[i];
}
}
if(matchCase2 !== null) return matchCase2;
if(matchCase3 !== null) return matchCase3;
return matchCase4;
}
console.log(getNextCard(player2, asztal[0]));
console.log(getNextCard(player3, asztal[0]));
console.log(getNextCard(player4, asztal[0]));
I'm running this program that makes a new array out of an old array of objects based on a few prompt questions. However when I run the program, if statement is not recognized in the for loop. The new array contains everything from the new array.
function verb(first,second,third,fourth,conjugation,chapter) {
this.first = first;
this.second = second;
this.third = third;
this.fourth = fourth;
this.conjugation = conjugation;
this.chapter = chapter;
}
// Now we can make an array of people
/*var family = new Array();
family[0] = new Person("alice", 40);
family[1] = new Person("bob", 42);
family[2] = new Person("michelle", 8);
// add the last family member, "timmy", who is 6 years old
family[3] = new Person("timmy", 6);*/
var family = new Array();
family[0] = new verb("amo","amare","amavi",'amatum',1,1);
family[1] = new verb("moneo","monere","monui","monitum",2,1);
family[2] = new verb("a "," a"," a","a ",3,6);
family[3] = new verb("debeo","debere","debui","debitum",2,1);
family[4] = new verb("do","dare","dedi","datum",1,1);
family[5] = new verb("servo","servare","servavi","servatum",1,1);
family[6] = new verb("conservo","conservare","conservavi","conservatum",1,1);
family[7] = new verb("terreo","terrere","terrui","territum",1,1);
family[8] = new verb("valeo","valere","valui","valitum",2,1);
family[9] = new verb("video","videre","vid","visum",2,1);
family[10] = new verb("voco","vocare","vocavi","vocatum",1,1);
family[11] = new verb("habeo","habere","habui","habitum",2,3);
family[12] = new verb("satio","satiare","satiavi","satiatum",1,3);
family[13] = new verb("culp","culpare","culpavi","culpatum",1,5);
family[14] = new verb(" ceno","cenare","cenavi","cenatum",1,5);
family[15] = new verb("maneo","manere","mansi","mansum",2,5);
family[16] = new verb("supero","supweare","superavi","superatum",1,5);
family[17] = new verb("tolero","tolerare","toleravi","toleratum",1,6);
family[18] = new verb("audeo","audere","ausus sum"," ",2,7);
family[19] = new verb("neco","necare","necavi","necatum",1,7);
family[20] = new verb("ago","agere","egi","actum",3,8);
var choose = prompt("do you want principle parts ?");
/*<?php echo $_POST["name"]; ?>
/*family[1] = new verb
family[2] = new verb
family[0].chapter
/*"var doceo = {
definition:"to teach",
first:"doceo",
second:"docere",
third:"dixi",
fourth:"doctum"
chapter:"3""*/
/*chap_beg = document.getElementById("0").submit;
chap_end = document.getElementByID("1").submit;*/
var chap_beg = prompt("What chapter do you want to begin?");
/*var chap_beg = <?php echo $_POST["name"]; ?>*/
var chap_end = prompt("what chapter do you want too end");
/* var chap_end = <?php echo $_POST["name"]; ?>*/
/*if((Math.random())*6<1){
person = 1;
}else if(1<(Math.random())*6<2){
person = 2;
}else if(2<(Math.random())*6<3){
person = 3;
}else if(3<(Math.random())*6<4){
person = 4;
}else if(4<(Math.random())*6<5){
person = 5;
}else if(5<(Math.random())*6<5){
person = 6;
} */
var helparray = new Array();
helparray[1]=1;
helparray[2]=2;
helparray[3]=3;
helparray[4]=4;
helparray[5]=5;
helparray[6]=6;
var person = helparray[Math.floor(Math.random() * helparray.length)];
var randselect = new Array();
for(i=0;i<family.length;i++) {
if( chap_beg < family[i].chapter < chap_end) {
console.log(family[i].first);
randselect.push(family[i]);
}else{
console.log("no");
}
/* console.log(randselect[randselect.length-1]);*/
}
var rand = randselect[Math.floor(Math.random() * (randselect.length - 1))];
/*var rand = randselect[Math.round(Math.random() * (randselect.length - 1))];*/`enter code here`
Yielding
amo
moneo
a
debeo
do
servo
conservo
terreo
valeo
video
voco
habeo
satio
culp
ceno
maneo
supero
tolero
audeo
neco
ago
This line...
if( chap_beg < family[i].chapter < chap_end) {
Should be
if( chap_beg < family[i].chapter && family[i].chapter < chap_end) {