Browse Source

HW_12 done

ostapenkonataliia 1 year ago
parent
commit
35783720d9
3 changed files with 12 additions and 26 deletions
  1. 4 10
      .idea/workspace.xml
  2. 7 15
      Js_12/js.js
  3. 1 1
      Js_12/style.css

+ 4 - 10
.idea/workspace.xml

@@ -2,16 +2,9 @@
 <project version="4">
   <component name="ChangeListManager">
     <list default="true" id="c45bf7d2-992f-400a-8194-6f236ee5f805" name="Changes" comment="">
-      <change afterPath="$PROJECT_DIR$/Js_12/index.html" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/Js_12/js.js" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/Js_12/style.css" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/rgb.js" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/Js _11/index.html" beforeDir="false" afterPath="$PROJECT_DIR$/Js _11/index.html" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/Js _11/js.js" beforeDir="false" afterPath="$PROJECT_DIR$/Js _11/js.js" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/Js_08/js.js" beforeDir="false" afterPath="$PROJECT_DIR$/Js_08/js.js" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/Js_10/js.js" beforeDir="false" afterPath="$PROJECT_DIR$/Js_10/js.js" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/js.js" beforeDir="false" afterPath="$PROJECT_DIR$/js.js" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/Js_12/js.js" beforeDir="false" afterPath="$PROJECT_DIR$/Js_12/js.js" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/Js_12/style.css" beforeDir="false" afterPath="$PROJECT_DIR$/Js_12/style.css" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -45,7 +38,7 @@
     "RunOnceActivity.OpenProjectViewOnStart": "true",
     "RunOnceActivity.ShowReadmeOnStart": "true",
     "WebServerToolWindowFactoryState": "false",
-    "last_opened_file_path": "C:/вика/js11",
+    "last_opened_file_path": "C:/A-Level/JS",
     "list.type.of.created.stylesheet": "CSS",
     "nodejs_package_manager_path": "npm",
     "settings.editor.selected.configurable": "project.propVCSSupport.DirectoryMappings",
@@ -94,6 +87,7 @@
       <workItem from="1670226413389" duration="30307000" />
       <workItem from="1670585530619" duration="66786000" />
       <workItem from="1670959529015" duration="10774000" />
+      <workItem from="1671047485199" duration="1057000" />
     </task>
     <servers />
   </component>

+ 7 - 15
Js_12/js.js

@@ -22,7 +22,7 @@ function createStore(reducer) {
     }
 }
 
-function reducer(state, {type, productName, productAmount, summ}){
+function reducer(state, {type, productName, productAmount, sum}){
     if (!state){ //начальная уборка в ларьке:
         return {
             пиво: {
@@ -37,29 +37,26 @@ function reducer(state, {type, productName, productAmount, summ}){
                 amount: 100,
                 price: 90,
             },
-            касса: 0
         }
     }
-    if (type === 'Купить' && productAmount <= state[productName].amount && summ >= state[productName].price * productAmount){ //если тип action - КУПИТЬ, то:
+    if (type === 'Купить' && productAmount <= state[productName].amount && sum >= state[productName].price * productAmount){ //если тип action - КУПИТЬ, то:
         return {
             ...state, //берем все что было из ассортимента
             [productName]: {
                 amount: state[productName].amount - productAmount,
                 price: state[productName].price
             },
-            касса: state.касса + state[productName].price * productAmount
-            //и уменьшаем то, что покупается на количество
         }
     }
     return state //если мы не поняли, что от нас просят в `action` - оставляем все как есть
 }
 
-function actionCreator (type, productName, productAmount, summ){
+function actionCreator (type, productName, productAmount, sum){
     return {
         type,
         productName,
         productAmount,
-        summ
+        sum
     }
 }
 
@@ -100,7 +97,6 @@ buttonBuy.onclick = () => {
 }
 
 for (const product in store.getState()){
-    if (product === 'касса') continue
 
     const productCard = document.createElement('div')
     productCard.classList.add('productCard')
@@ -121,16 +117,12 @@ for (const product in store.getState()){
     showCase.append(productCard)
 
     const productOption = document.createElement('option')
-    productOption.value = productOption.innerText = product
+    productOption.innerText = product
     productSelect.append(productOption)
 
-    const productPriceUnsubscribe = store.subscribe( () => {
-        productPrice.innerText = store.getState()[product].price + ' грн'
-    })
-
-    const productQuantityUnsubscribe = store.subscribe( () => {
+    const productAmountChange= store.subscribe( () => {
         productAmount.innerText = store.getState()[product].amount + ' шт'
-    } )
+    })
 }
 
 

+ 1 - 1
Js_12/style.css

@@ -17,7 +17,7 @@ body {
 
 .productCard{
     padding: 10px;
-    margin: 20px 20px 20px 0;
+    margin: 10px 10px 10px 0;
     width: 150px;
     height: 150px;
     background-color: #c083ef;