@@ -968,51 +968,52 @@ <h3>${proj.title}</h3>
968968
969969 // Update counts
970970 const total = projectsData . length ;
971- function animateCounter ( id , value ) {
972-
973- let start = 0 ;
974-
975- const element = document . getElementById ( id ) ;
976-
977- const timer = setInterval ( ( ) => {
978-
979- start ++ ;
980-
981- element . textContent = start ;
982-
983- if ( start >= value ) {
984-
985- clearInterval ( timer ) ;
986-
987- }
988-
989- } , 25 ) ;
971+ function animateCounter ( id , value ) {
972+ const element = document . getElementById ( id ) ;
973+ if ( ! element ) return ;
974+
975+ let start = 0 ;
976+ // If target value is 0, set immediately and exit
977+ if ( value <= 0 ) {
978+ element . textContent = "0" ;
979+ return ;
980+ }
990981
991- }
982+ const timer = setInterval ( ( ) => {
983+ start ++ ;
984+ element . textContent = start ;
985+ if ( start >= value ) {
986+ clearInterval ( timer ) ;
987+ }
988+ } , 25 ) ;
989+ }
992990 const games = projectsData . filter ( ( p ) => p . category === "games" ) . length ;
993991 const math = projectsData . filter ( ( p ) => p . category === "math" ) . length ;
994992 const utils = projectsData . filter (
995993 ( p ) => p . category === "utilities"
996994 ) . length ;
997995
998- const heroCount = document . getElementById ( "heroProjectCount" ) ;
999- const heroGames = document . getElementById ( "heroGameCount" ) ;
1000- const heroMath = document . getElementById ( "heroMathCount" ) ;
1001- const heroUtils = document . getElementById ( "heroUtilityCount" ) ;
1002996 const projectBadge = document . getElementById ( "projectCountBadge" ) ;
1003-
1004- if ( heroCount ) heroCount . textContent = total ;
1005- if ( heroGames ) heroGames . textContent = games ;
1006- if ( heroMath ) heroMath . textContent = math ;
1007- if ( heroUtils ) heroUtils . textContent = utils ;
1008997 if ( projectBadge ) projectBadge . textContent = total + " projects" ;
1009- animateCounter ( "statsTotal" , total ) ;
1010- animateCounter ( "statsGames" , games ) ;
1011- animateCounter ( "statsMath" , math ) ;
1012- animateCounter ( "statsUtilities" , utils ) ;
1013- document . getElementById ( "statsFavorites" ) . textContent = favorites . length ;
1014- const viewed = JSON . parse ( localStorage . getItem ( "recentlyViewed" ) || "[]" ) ;
1015- animateCounter ( "statsViewed" , viewed . length ) ;
998+
999+ // Animate the actual hero counters that exist on the page
1000+ animateCounter ( "heroProjectCount" , total ) ;
1001+ animateCounter ( "heroGameCount" , games ) ;
1002+ animateCounter ( "heroMathCount" , math ) ;
1003+ animateCounter ( "heroUtilityCount" , utils ) ;
1004+ animateCounter ( "heroFavoriteCount" , favorites . length ) ;
1005+
1006+ const viewed = JSON . parse ( localStorage . getItem ( "recentlyViewed" ) || "[]" ) ;
1007+ animateCounter ( "heroViewedCount" , viewed . length ) ;
1008+
1009+ // Safe updates for the statistics dashboard cards in case they exist
1010+ animateCounter ( "statsTotal" , total ) ;
1011+ animateCounter ( "statsGames" , games ) ;
1012+ animateCounter ( "statsMath" , math ) ;
1013+ animateCounter ( "statsUtilities" , utils ) ;
1014+ const statsFavoritesEl = document . getElementById ( "statsFavorites" ) ;
1015+ if ( statsFavoritesEl ) statsFavoritesEl . textContent = favorites . length ;
1016+ animateCounter ( "statsViewed" , viewed . length ) ;
10161017
10171018 console . log (
10181019 `✅ Loaded ${ total } projects: ${ games } games, ${ math } math, ${ utils } utilities`
0 commit comments