I have set up a function to get the current date and time in the format I want:
function date(){
var d = new Date();
var minutes = d.getMinutes();
var month = d.getMonth() +1;
if(minutes<10){
return (d.getDate() + "/" + month + "/" + d.getFullYear() + " " + d.getHours() + ":" + "0" + minutes);
}else{
return (d.getDate() + "/" + month + "/" + d.getFullYear() + " " + d.getHours() + ":" + minutes);}
}
I created an Object that takes the values (amount,date,type). How can I set it up so with every new instance of the object the date value be generated by the function date() automatically so that when it gets pushed to the array movements a timestamp is added?
Here is my code:
var movements =[];
//transactions
var initialBalance = new Transaction(1000,"date","cash");
var addIn = new Transaction(500,"date","cash");
var addOut = new Transaction(-300,"date","card");
//add the transactions to the movements array
movements.unshift(initialBalance);
movements.push(addIn);
movements.push(addOut);
I would like to do this with pure JS.
Transaction?Object's constructor to call thedate()function and store it?