How to code a buzzer in.

I currently have a 7 segment display on an adruino nano setup to click count from 0 to 9. I am trying to get an audible tone when the number 9 is displayed. I am pretty new to this and don’t complete understanding the code writing process. I would like to use pin 12 with a piezoelectric buzzer. bellow is the code used that I found on the internet.

Any help would be greatly appreciated! Thank you.

[color=#333333][color=#87ceeb]/* 
Arduino 7-Segment LED Display for Common Cathode Displays
Arduino Pins: 2,3,4,5,6,7,8
Display Pins: 7,6,4,2,1,9,10
Display Pins 3&8 should go to GND
Switch Input is at Pin 9
Source: https://www.electroschematics.com/9636/arduino-segment-display-counter/
*/[/color]
[color=#f0e68c][b]byte[/b][/color][color=#ffffff] numbers[/color][color=#ffffff][[/color][color=#cd5c5c]10[/color][color=#ffffff]][/color] [color=#ffffff]=[/color] [color=#ffffff]{[/color][color=#ffffff] 
 B11111100[/color][color=#ffffff],[/color][color=#ffffff] B01100000[/color][color=#ffffff],[/color][color=#ffffff] B11011010[/color][color=#ffffff],[/color][color=#ffffff] B11110010[/color][color=#ffffff],[/color][color=#ffffff] B01100110[/color][color=#ffffff],[/color][color=#ffffff] 
 B10110110[/color][color=#ffffff],[/color][color=#ffffff] B10111110[/color][color=#ffffff],[/color][color=#ffffff] B11100000[/color][color=#ffffff],[/color][color=#ffffff] B11111110[/color][color=#ffffff],[/color][color=#ffffff] B11100110 
 [/color][color=#ffffff]};[/color]
[color=#f0e68c][b]void[/b][/color][color=#ffffff] setup[/color][color=#ffffff]()[/color] [color=#ffffff]{[/color] 
 [color=#f0e68c][b]for[/b][/color][color=#ffffff]([/color][color=#f0e68c][b]int[/b][/color][color=#ffffff] i [/color][color=#ffffff]=[/color] [color=#cd5c5c]2[/color][color=#ffffff];[/color][color=#ffffff] i [/color][color=#ffffff]<=[/color] [color=#cd5c5c]8[/color][color=#ffffff];[/color][color=#ffffff] i[/color][color=#ffffff]++)[/color] [color=#ffffff]{[/color][color=#ffffff]
 pinMode[/color][color=#ffffff]([/color][color=#ffffff]i[/color][color=#ffffff],[/color][color=#ffffff] OUTPUT[/color][color=#ffffff]);[/color] 
 [color=#ffffff]}[/color][color=#ffffff]
 pinMode[/color][color=#ffffff]([/color][color=#cd5c5c]9[/color][color=#ffffff],[/color][color=#ffffff] INPUT[/color][color=#ffffff]);[/color]
[color=#ffffff]}[/color]

[color=#f0e68c][b]int[/b][/color][color=#ffffff] counter [/color][color=#ffffff]=[/color] [color=#cd5c5c]0[/color][color=#ffffff];[/color]
[color=#f0e68c][b]bool[/b][/color][color=#ffffff] go_by_switch [/color][color=#ffffff]=[/color] [color=#f0e68c][b]true[/b][/color][color=#ffffff];[/color]
[color=#f0e68c][b]int[/b][/color][color=#ffffff] last_input_value [/color][color=#ffffff]=[/color][color=#ffffff] LOW[/color][color=#ffffff];[/color]

[color=#f0e68c][b]void[/b][/color][color=#ffffff] loop[/color][color=#ffffff]()[/color] [color=#ffffff]{[/color]
 [color=#f0e68c][b]if[/b][/color][color=#ffffff]([/color][color=#ffffff]go_by_switch[/color][color=#ffffff])[/color] [color=#ffffff]{[/color]
 [color=#f0e68c][b]int[/b][/color][color=#ffffff] switch_input_value [/color][color=#ffffff]=[/color][color=#ffffff] digitalRead[/color][color=#ffffff]([/color][color=#cd5c5c]9[/color][color=#ffffff]);[/color]
 [color=#f0e68c][b]if[/b][/color][color=#ffffff]([/color][color=#ffffff]last_input_value [/color][color=#ffffff]==[/color][color=#ffffff] LOW [/color][color=#ffffff]&&[/color][color=#ffffff] switch_input_value [/color][color=#ffffff]==[/color][color=#ffffff] HIGH[/color][color=#ffffff])[/color] [color=#ffffff]{[/color][color=#ffffff]
 counter [/color][color=#ffffff]=[/color] [color=#ffffff]([/color][color=#ffffff]counter [/color][color=#ffffff]+[/color] [color=#cd5c5c]1[/color][color=#ffffff])[/color] [color=#ffffff]%[/color] [color=#cd5c5c]10[/color][color=#ffffff];[/color]
 [color=#ffffff]}[/color][color=#ffffff]
 last_input_value [/color][color=#ffffff]=[/color][color=#ffffff] switch_input_value[/color][color=#ffffff];[/color]
 [color=#ffffff]}[/color] [color=#f0e68c][b]else[/b][/color] [color=#ffffff]{[/color][color=#ffffff]
 delay[/color][color=#ffffff]([/color][color=#cd5c5c]500[/color][color=#ffffff]);[/color][color=#ffffff] 
 counter [/color][color=#ffffff]=[/color] [color=#ffffff]([/color][color=#ffffff]counter [/color][color=#ffffff]+[/color] [color=#cd5c5c]1[/color][color=#ffffff])[/color] [color=#ffffff]%[/color] [color=#cd5c5c]10[/color][color=#ffffff];[/color]
 [color=#ffffff]}[/color][color=#ffffff]
 writeNumber[/color][color=#ffffff]([/color][color=#ffffff]counter[/color][color=#ffffff]);[/color]
[color=#ffffff]}[/color]

[color=#f0e68c][b]void[/b][/color][color=#ffffff] writeNumber[/color][color=#ffffff]([/color][color=#f0e68c][b]int[/b][/color][color=#ffffff] number[/color][color=#ffffff])[/color] [color=#ffffff]{[/color]
 [color=#f0e68c][b]if[/b][/color][color=#ffffff]([/color][color=#ffffff]number [/color][color=#ffffff]<[/color] [color=#cd5c5c]0[/color] [color=#ffffff]||[/color][color=#ffffff] number [/color][color=#ffffff]>[/color] [color=#cd5c5c]9[/color][color=#ffffff])[/color] [color=#ffffff]{[/color]
 [color=#f0e68c][b]return[/b][/color][color=#ffffff];[/color]
 [color=#ffffff]}[/color]
 [color=#f0e68c][b]byte[/b][/color][color=#ffffff] mask [/color][color=#ffffff]=[/color][color=#ffffff] numbers[/color][color=#ffffff][[/color][color=#ffffff]number[/color][color=#ffffff]];[/color]
 [color=#f0e68c][b]byte[/b][/color][color=#ffffff] currentPinMask [/color][color=#ffffff]=[/color][color=#ffffff] B10000000[/color][color=#ffffff];[/color]
 [color=#f0e68c][b]for[/b][/color][color=#ffffff]([/color][color=#f0e68c][b]int[/b][/color][color=#ffffff] i [/color][color=#ffffff]=[/color] [color=#cd5c5c]2[/color][color=#ffffff];[/color][color=#ffffff] i [/color][color=#ffffff]<=[/color] [color=#cd5c5c]8[/color][color=#ffffff];[/color][color=#ffffff] i[/color][color=#ffffff]++)[/color] [color=#ffffff]{[/color] [color=#f0e68c][b]if[/b][/color][color=#ffffff]([/color][color=#ffffff]mask [/color][color=#ffffff]&[/color][color=#ffffff] currentPinMask[/color][color=#ffffff])[/color][color=#ffffff] digitalWrite[/color][color=#ffffff]([/color][color=#ffffff]i[/color][color=#ffffff],[/color][color=#ffffff]HIGH[/color][color=#ffffff]);[/color] [color=#f0e68c][b]else[/b][/color][color=#ffffff] digitalWrite[/color][color=#ffffff]([/color][color=#ffffff]i[/color][color=#ffffff],[/color][color=#ffffff]LOW[/color][color=#ffffff]);[/color][color=#ffffff] currentPinMask [/color][color=#ffffff]=[/color][color=#ffffff] currentPinMask [/color][color=#ffffff]>>[/color] [color=#cd5c5c]1[/color][color=#ffffff];[/color]
 [color=#ffffff]}[/color][color=#ffffff] [/color][/color]

}

please use code tags (read forum rules). white text on grey background is not readable

study the tone() function to get your piezoelectric buzzer to beep when counter reaches 9

@awas

Do you really think it is appropriate to post your sketch text as white characters ?