From 8cbf09bcb5d3dd314a6e864d5b9cd08a05622276 Mon Sep 17 00:00:00 2001 From: Sajad Jalilian Date: Fri, 5 Jan 2024 11:44:32 +0330 Subject: [PATCH] Change input and add validation for date --- functions.js | 9 +++++++-- index.html | 19 +++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/functions.js b/functions.js index cec383b..b1516a8 100644 --- a/functions.js +++ b/functions.js @@ -9,9 +9,9 @@ function fetchData() { }); }; -function calculateSum(value, date) { +function calculateSum(value, year, month, day) { const rawData = this.data; - usdOnDate = rawData[date]["azadi1"]["sell"]; + usdOnDate = rawData[CreateDate(year, month, day)]["azadi1"]["sell"]; const keys = Object.keys(rawData); const lastKey = keys[keys.length - 1]; @@ -24,6 +24,11 @@ function calculateSum(value, date) { const rounded = Math.round(rialAtLastDate * 100) / 100; return { value: rounded, lastUsdValue: latestUsdValue, usdValueOnDate: usdOnDate } + + function CreateDate(year, month, day) { + date = `${year}/${month.padStart(2, '0')}/${day.padStart(2, '0')}`; + return date; + } }; function showData() { diff --git a/index.html b/index.html index fcc42a2..6862c18 100644 --- a/index.html +++ b/index.html @@ -33,12 +33,23 @@

پول واقعی

مبلغ را به تومان و تاریخ را به شمسی وارد کنید

-
+
- +
+ + + -