1

the task is to make a function that gives serial number to every new product so the new serial would concat the barcode with the serial but if the number is 10 it should shift to 11 (last digit zero not allowed) so the serial should be 1,2....9,11,12..19,21,22 but the product is 1,2,...11,11,12...21,21,22 I don't know why. sorry in advance if the reason is silly. that is the code:

barcode = '56734';
ary: string[] = [];
serial!: number;
finaly!: string;
newy(){  
   if (this.ary.length == 0){
    this.serial = 1
   }else if((this.ary.length + 1) %10 == 0){
    this.serial = this.ary.length + 2
   } else {
    this.serial = this.ary.length + 1
   }
   this.finaly = this.barcode + this.serial;
   this.ary.push(this.finaly)
   return this.ary   
}
startup
  • 13
  • 3
  • 1
    Welcome to Stack Overflow! This is a good opportunity for you to start familiarizing yourself with [using a debugger](https://stackoverflow.com/q/25385173/328193). When you step through the code in a debugger, which operation first produces an unexpected result? What were the values used in that operation? What was the result? What result was expected? Why? To learn more about this community and how we can help you, please start with the [tour] and read [ask] and its linked resources. – David Dec 20 '22 at 15:57
  • This looks like TypeScript, not JavaScript. – Barmar Dec 20 '22 at 16:33

1 Answers1

0

ok after hours of equations the answer is math rather than programming. that worked for me

barcode = '56734';
ary: string[] = [];
serial!: number;
finaly!: string;
newy(){    
   this.serial = this.ary.length +  1 + Math.floor(this.ary.length /9) 
   this.finaly = this.barcode + this.serial;   
   this.ary.push(this.finaly)
}
startup
  • 13
  • 3