(e)
| 6 | |
| 7 | //function to handle keyboard inputs |
| 8 | function keyboardInputHandler(e) { |
| 9 | //grabbing the liveScreen |
| 10 | let res = document.getElementById("result"); |
| 11 | |
| 12 | //numbers |
| 13 | if (e.key === "0") { |
| 14 | res.value += "0"; |
| 15 | } else if (e.key === "1") { |
| 16 | res.value += "1"; |
| 17 | } else if (e.key === "2") { |
| 18 | res.value += "2"; |
| 19 | } else if (e.key === "3") { |
| 20 | res.value += "3"; |
| 21 | } else if (e.key === "4") { |
| 22 | res.value += "4"; |
| 23 | } else if (e.key === "5") { |
| 24 | res.value += "5"; |
| 25 | } else if (e.key === "6") { |
| 26 | res.value += "6"; |
| 27 | } else if (e.key === "7") { |
| 28 | res.value += "7"; |
| 29 | } else if (e.key === "7") { |
| 30 | res.value += "7"; |
| 31 | } else if (e.key === "8") { |
| 32 | res.value += "8"; |
| 33 | } else if (e.key === "9") { |
| 34 | res.value += "9"; |
| 35 | } |
| 36 | |
| 37 | //operators |
| 38 | if (e.key === "+") { |
| 39 | res.value += "+"; |
| 40 | } else if (e.key === "-") { |
| 41 | res.value += "-"; |
| 42 | } else if (e.key === "*") { |
| 43 | res.value += "*"; |
| 44 | } else if (e.key === "/") { |
| 45 | res.value += "/"; |
| 46 | } |
| 47 | |
| 48 | //decimal key |
| 49 | if (e.key === ".") { |
| 50 | res.value += "."; |
| 51 | } |
| 52 | |
| 53 | //press enter to see result |
| 54 | if (e.key === "Enter") { |
| 55 | res.value = eval(result.value || null); |
| 56 | } |
| 57 | |
| 58 | //backspace for removing the last input |
| 59 | if (e.key === "Backspace") { |
| 60 | let resultInput = res.value; |
| 61 | |
| 62 | //remove the last element in the string |
| 63 | res.value = resultInput.substring(0, res.value.length - 1); |
| 64 | } |
| 65 | } |
nothing calls this directly
no outgoing calls
no test coverage detected