Varvara Huza преди 3 години
родител
ревизия
376dae9058
променени са 1 файла, в които са добавени 11 реда и са изтрити 16 реда
  1. 11 16
      Homework_12/main.js

+ 11 - 16
Homework_12/main.js

@@ -31,7 +31,7 @@ function reducer(state, {type, ШО, СКОКА, БАБЛО}){
             cash: 0
         }
     }
-    if (type === 'КУПИТЬ' && ШО in state.goods && БАБЛО >= state.goods[ШО].price && (СКОКА <= state.goods[ШО].count && СКОКА > 0)){ 
+    if (type === 'КУПИТЬ' && ШО in state.goods && БАБЛО >= state.goods[ШО].price * СКОКА && (СКОКА <= state.goods[ШО].count && СКОКА > 0)){ 
         return { 
             ...state,
             goods: {...state.goods, [ШО]: {...state.goods[ШО], count: state.goods[ШО].count - СКОКА}},
@@ -62,11 +62,11 @@ const showImages = () => {
     showcase.innerHTML = ''
     let beerImg = document.createElement('img')
     let beerQuantity = store.getState().goods.пиво.count
-    if (beerQuantity >= 85) {
+    if (beerQuantity >= 80) {
         beerImg.src = 'images/beerMany.jpg'
-    } else if (beerQuantity >= 50) {
+    } else if (beerQuantity >= 40) {
         beerImg.src = 'images/beerMiddle.png'
-    } else if (beerQuantity >= 20) {
+    } else if (beerQuantity > 0) {
         beerImg.src = 'images/beerLittle.jpg'
     } else if (beerQuantity === 0) {
         beerImg.src = 'images/beerNone.jpg'
@@ -74,11 +74,11 @@ const showImages = () => {
 
     let chipsImg = document.createElement('img')
     let chipsQuantity = store.getState().goods.чипсы.count
-    if (chipsQuantity >= 85) {
+    if (chipsQuantity >= 80) {
         chipsImg.src = 'images/chipsMany.jpg'
-    } else if (chipsQuantity >= 50) {
+    } else if (chipsQuantity >= 40) {
         chipsImg.src = 'images/chipsMiddle.jpg'
-    } else if (chipsQuantity >= 20) {
+    } else if (chipsQuantity > 0) {
         chipsImg.src = 'images/chipsLittle.png'
     } else if (chipsQuantity === 0) {
         chipsImg.src = 'images/chipsNone.jpg'
@@ -86,11 +86,11 @@ const showImages = () => {
 
     let cigsImg = document.createElement('img')
     let cigsQuantity = store.getState().goods.сиги.count
-    if (cigsQuantity >= 85) {
+    if (cigsQuantity >= 80) {
         cigsImg.src = 'images/cigsMany.jpg'
-    } else if (cigsQuantity >= 50) {
+    } else if (cigsQuantity >= 40) {
         cigsImg.src = 'images/cigsMiddle.jpg'
-    } else if (cigsQuantity >= 20) {
+    } else if (cigsQuantity > 0) {
         cigsImg.src = 'images/cigsLittle.jpg'
     } else if (cigsQuantity === 0) {
         cigsImg.src = 'images/cigsNone.jpg'
@@ -136,9 +136,4 @@ buy.onclick = () => {
 store.subscribe(() => console.log(store.getState())) 
 store.subscribe(() => {quantity.value = '', money.value = ''})
 store.subscribe(showQuantity)
-store.subscribe(showImages)
-
-
-
-//происходит запуск редьюсера, который создает новый state. 
-//dispatch запускает всех подписчиков из массива cbs
+store.subscribe(showImages)