-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.js
99 lines (68 loc) · 1.99 KB
/
convert.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
function convertTemperature(chosen) {
let celciusInput , fahrenheitValue = 0;
//calculate conversion based on selection
switch (chosen) {
case 'celcius' :
celciusInput = $('.input').val();
console.log(celciusInput)
if ( (!($.isNumeric(celciusInput))) || (celciusInput == "") ) {
alert('Please enter a Number');
return;
}
fahrenheitValue = Math.floor(celciusInput * 9 / 5 + 32);
return fahrenheitValue.toFixed(2) + '°F';
break;
case 'fahrenheit':
fahrenheitValue = $('.input').val();
if ((!($.isNumeric(fahrenheitValue))) || fahrenheitValue == "") {
alert('Please enter a Number');
$('#result').text(' ');
return;
}
celciusInput = Math.floor((fahrenheitValue - 32) * 5 / 9);
return celciusInput.toFixed(2) + '°C';
break;
}
}
$(document).ready(function() {
$('input[name="convert"]').on('click', function () {
//make a selection of conversion
let decision = $('input[name="convert"]:checked').val();
console.log(decision);
//display the response div and the submit button
$('#response, #submit').css({'display': 'block'});
$('#submit').on('click', function(ev) {
ev.preventDefault();
var conVal = convertTemperature(decision);
if(conVal != undefined) $('#result').text('Result is ' + conVal);
$(this).text('Make Another conversion');
$(this).on('click', function () {
location.reload(true);
});
/*
let originalValue = $('#submit').text('Submit');
if (originalValue == 'Submit') {
console.log(originalValue);
$(this).text('Make Another conversion');
location.reload(true);
}
else{
$(this).text('Submit');
}
*/
});
});
/*
$('#submit').on('click', function(e) {
e.preventDefault();
let originalValue = $(this).prop('text','Submit');
if (originalValue == 'Submit') {
$(this).text('Make Another conversion');
location.reload(true);
}
else{
$(this).text('Submit');
}
})
*/
});