-
Notifications
You must be signed in to change notification settings - Fork 0
/
scriptDay07.js
76 lines (62 loc) · 2.75 KB
/
scriptDay07.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//Calculator
let loop = 1
function sum(convertFirstValue,convertSecondValue){
return convertFirstValue+convertSecondValue
}
function multiply(convertFirstValue,convertSecondValue){
return convertFirstValue*convertSecondValue
}
function subtract(convertFirstValue,convertSecondValue){
return convertFirstValue-convertSecondValue
}
function divide(convertFirstValue,convertSecondValue){
return convertFirstValue/convertSecondValue
}
while(loop == 1){
let options = prompt("Escolha uma opção: (1) Somar | (2) Multiplicar | (3) Subtrair | (4) Dividir | (5) Sair")
let getOptions = options
let firstValue = ''
let convertFirstValue = ''
let secondValue = ''
let convertSecondValue = ''
switch(getOptions){
case '1':
firstValue = prompt("Digite o primeiro valor da soma:")
convertFirstValue = parseFloat(firstValue)
secondValue = prompt("Digite o segundo valor da soma:")
convertSecondValue = parseFloat(secondValue)
let sumFunction = sum(convertFirstValue,convertSecondValue)
alert(`${convertFirstValue} + ${convertSecondValue} = ${sumFunction}`)
break
case '2':
firstValue = prompt("Digite o primeiro valor da multiplicação:")
convertFirstValue = parseFloat(firstValue)
secondValue = prompt("Digite o segundo valor da multiplicação:")
convertSecondValue = parseFloat(secondValue)
let multiplyFunction = multiply(convertFirstValue,convertSecondValue)
alert(`${convertFirstValue} x ${convertSecondValue} = ${multiplyFunction}`)
break
case '3':
firstValue = prompt("Digite o primeiro valor da subtração:")
convertFirstValue = parseFloat(firstValue)
secondValue = prompt("Digite o segundo valor da subtração:")
convertSecondValue = parseFloat(secondValue)
let subtractFunction = subtract(convertFirstValue, convertSecondValue)
alert(`${convertFirstValue} - ${convertSecondValue} = ${subtractFunction}`)
break
case '4':
firstValue = prompt("Digite o primeiro valor da divisão:")
convertFirstValue = parseFloat(firstValue)
secondValue = prompt("Digite o segundo valor da divisão:")
convertSecondValue = parseFloat(secondValue)
let divideFunction = divide(convertFirstValue,convertSecondValue)
alert(`${convertFirstValue} / ${convertSecondValue} = ${divideFunction}`)
break
case '5':
loop = 0
alert("Até mais!")
break
default:
alert("Opção não encontrada!")
}
}