From 91e428e563672c354c15a601d68dd640dbc8b8a0 Mon Sep 17 00:00:00 2001 From: Mike Bryant Date: Tue, 7 Apr 2020 17:39:15 +0100 Subject: [PATCH] More fixes --- js/scripts.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/js/scripts.js b/js/scripts.js index 853ae93..508ebb2 100644 --- a/js/scripts.js +++ b/js/scripts.js @@ -59,7 +59,7 @@ const updateLocalStorage = function (data) { } const isEmpty = function (arr) { - const filtered = arr.filter(value => value !== null && value !== '') + const filtered = arr.filter(value => value !== null && value !== '' && !isNaN(value)) return filtered.length == 0 } @@ -75,12 +75,12 @@ const getPrices = function () { const getSellPrices = function () { //Checks all sell inputs and returns an array with their values return res = sell_inputs.map(function (input) { - return input.value || '' + return parseInt(input.value || ''); }) } const calculateOutput = function (data) { - if (isEmpty(data.slice(2))) { + if (isEmpty(data)) { $("#output").html(""); return; } @@ -102,11 +102,11 @@ const calculateOutput = function (data) { } const update = function () { - const sell_prices = getSellPrices() - const buy_price = buy_input.val() - const data = [buy_price, buy_price, ...sell_prices] - updateLocalStorage(data) - calculateOutput(data) + const sell_prices = getSellPrices(); + const buy_price = parseInt(buy_input.val()); + const data = [buy_price, buy_price, ...sell_prices]; + updateLocalStorage(data); + calculateOutput(data); } $(document).ready(initialize);