|
| 1 | +'use-strict'; |
| 2 | +const input = document.querySelector('.input'); |
| 3 | +const displayTotal = document.querySelector('.result'); |
| 4 | +const resultElevy = document.querySelector('.result-elevy'); |
| 5 | +const networkFee = document.querySelector('.network'); |
| 6 | +const inputType = document.querySelector('.form__input--type'); |
| 7 | +const network = document.querySelector('.network__voda'); |
| 8 | +const resultField = document.querySelector('.total-display'); |
| 9 | + |
| 10 | +displayTotal.textContent = `GH¢ ${0}`; |
| 11 | +networkFee.textContent = `GH¢ ${0}`; |
| 12 | + |
| 13 | +input.addEventListener('input', (e) => { |
| 14 | + e.preventDefault(); |
| 15 | + const amount = Number(input.value); |
| 16 | + if (inputType.value === 'MTN') { |
| 17 | + if (amount > 50 && amount <= 1000) { |
| 18 | + const momoCharge = amount * (0.75 / 100); |
| 19 | + networkFee.textContent = `GH¢ ${momoCharge.toFixed(2)}`; |
| 20 | + } |
| 21 | + if (amount <= 50) networkFee.textContent = `GH¢ ${0.38}`; |
| 22 | + if (amount > 1000) networkFee.textContent = `GH¢ ${7.5}`; |
| 23 | + } |
| 24 | + if (amount > 100) { |
| 25 | + const elevy = amount * 0.015; |
| 26 | + const result = elevy + amount; |
| 27 | + displayTotal.textContent = `GH¢ ${result.toFixed(2)}`; |
| 28 | + resultElevy.textContent = `GH¢ ${elevy.toFixed(2)}`; |
| 29 | + } else { |
| 30 | + displayTotal.textContent = `GH¢ ${amount}`; |
| 31 | + resultElevy.textContent = `GH¢ ${0}`; |
| 32 | + } |
| 33 | +}); |
| 34 | + |
| 35 | +inputType.addEventListener('change', (e) => { |
| 36 | + e.preventDefault(); |
| 37 | + if (inputType.value === 'vodafone') { |
| 38 | + input.value = ''; |
| 39 | + displayTotal.textContent = `GH¢ ${0}`; |
| 40 | + resultElevy.textContent = `GH¢ ${0}`; |
| 41 | + networkFee.textContent = `GH¢ ${0}`; |
| 42 | + network.classList.remove('hidden'); |
| 43 | + inputType.style.border = '3.5px solid white'; |
| 44 | + input.style.border = '5px solid white'; |
| 45 | + resultField.style.border = '3.5px solid white'; |
| 46 | + document.body.style.backgroundColor = 'rgb(228, 44, 44)'; |
| 47 | + } |
| 48 | + |
| 49 | + if (inputType.value === 'MTN') { |
| 50 | + input.value = ''; |
| 51 | + displayTotal.textContent = `GH¢ ${0}`; |
| 52 | + resultElevy.textContent = `GH¢ ${0}`; |
| 53 | + network.classList.remove('hidden'); |
| 54 | + inputType.style.border = '3.5px solid rgb(10, 66, 110)'; |
| 55 | + input.style.border = '3.5px solid rgb(10, 66, 110)'; |
| 56 | + resultField.style.border = '3.5px solid rgb(10, 66, 110)'; |
| 57 | + document.body.style.backgroundColor = 'rgb(234, 206, 9)'; |
| 58 | + } |
| 59 | + if (inputType.value === 'select') { |
| 60 | + document.querySelector('.network__voda').classList.add('hidden'); |
| 61 | + document.body.style.backgroundColor = 'rgb(159, 154, 154)'; |
| 62 | + } |
| 63 | +}); |
0 commit comments