1- import { getPredictions , clearPredictions } from "../js/predictionStorage.js" ;
1+ import {
2+ getPredictions ,
3+ clearPredictions ,
4+ comparePredictions
5+ } from "../js/predictionStorage.js" ;
26
37export default function RecentPredictions ( ) {
48 const history = getPredictions ( ) ;
@@ -11,16 +15,35 @@ export default function RecentPredictions() {
1115 container . appendChild ( title ) ;
1216
1317 history . forEach ( ( item , i ) => {
14- const div = document . createElement ( "div" ) ;
15- div . className = "prediction-item" ;
16- div . innerHTML = `
17- <p><strong>${ item . timestamp } </strong></p>
18- <p>Input: ${ item . input } </p>
19- <p>Output: ${ item . output } </p>
20- ` ;
21- container . appendChild ( div ) ;
22- } ) ;
18+ const div = document . createElement ( "div" ) ;
19+ div . className = "prediction-item" ;
2320
21+ div . innerHTML = `
22+ <p><strong>${ item . timestamp } </strong></p>
23+ <p>Input: ${ item . input } </p>
24+ <p>Output: ${ item . output } </p>
25+ ` ;
26+
27+ const compareBtn = document . createElement ( "button" ) ;
28+ compareBtn . textContent = "Compare" ;
29+
30+ compareBtn . onclick = ( ) => {
31+ if ( i + 1 < history . length ) {
32+ const result = comparePredictions ( i + 1 , i ) ;
33+
34+ alert (
35+ `Previous Output: ${ result . previous . output }
36+ Latest Output: ${ result . latest . output } `
37+ ) ;
38+ } else {
39+ alert ( "No previous prediction available" ) ;
40+ }
41+ } ;
42+
43+ div . appendChild ( compareBtn ) ;
44+
45+ container . appendChild ( div ) ;
46+ } ) ;
2447 if ( history . length > 0 ) {
2548 const clearBtn = document . createElement ( "button" ) ;
2649 clearBtn . textContent = "Clear History" ;
0 commit comments