After successfully writing the code in Java, I am now attempting to write it in JavaScript. Here is the current Java code:
public class CarGallery {
static int carCounter=10;
static Gallery[] car = new Gallery[carCounter];
public static void main(String[] args) {
car[0].weight = (float) 1.25;
car[0].weight = (float) 0.87;
// ... and so on ... //
}
}
class Gallery {
public float weight;
public float height;
public int colorCode;
public int stockGallery;
};
Below is my attempt at replicating the Java code in JavaScript, which currently does not work:
var cars = {weight:0 , height:0 , stock:0 , model:"..."};
var cars = new Array();
cars[0].weight=1.2;
cars[0].height=0.87;
cars[0].stock=2;
cars[0].model="320";
- Upon further research, I discovered that there isn't a direct equivalent of classes in JavaScript like there is in Java.
- In JavaScript, class-like behavior can be achieved using constructors, however, I prefer not to use constructors.
The member should be defined as an array as seen here in the Java code:
static Gallery[] car = new Gallery[carCounter];
Any assistance or guidance you can provide would be greatly appreciated!