-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpracticeProblem1.js
More file actions
136 lines (98 loc) · 3.16 KB
/
practiceProblem1.js
File metadata and controls
136 lines (98 loc) · 3.16 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* http://www.w3resource.com/javascript-exercises/javascript-basic-exercises.php
* This is a JavaScript Scratchpad.a
*
* Enter some JavaScript, then Right Click or choose from the Execute Menu:
* 1. Run to evaluate the selected text (Ctrl+R),
* 2. Inspect to bring up an Object Inspector on the result (Ctrl+I), or,
* 3. Display to insert the result in a comment after the selection. (Ctrl+L)
*/
var d = new Date();
console.log("Today is : "+ d.getDay());
console.log("Current Time is : " + d.getHours()+":" + d.getMinutes()+ ":" + d.getSeconds());
//window.print();
var aTri = function(a,b,c){
var p = (a + b + c)/2;
var ans = Math.sqrt(p*(p-a)*(p-b)*(p-c));
return ans;
};
console.log(aTri(5,6,7));
var reverse = function(string){
var firstLetter = string.charAt(0);
var result = string;
for(var i=0; i < string.length;i++){
var lastLetter = string.slice(string.length - 1);
string = string.slice(string.length - 1);
//console.log(lastLetter);
string = lastLetter + string.substring(string.indexOf(firstLetter, (string.length - 1)));
}
return string;
}
var str = "abcd";
//console.log(str.slice(0,0));
//console.log(reverse('abcd'));
//console.log(reverse("abcd")); come back
var isLeapYear = function(year){
if(year % 4 == 0){
return true;
}
else{
return false;
}
}
console.log(isLeapYear(4));
var findSunday = function(start, end){
for(var year = start; year <= end; year++){
var dt = new Date(year, 0, 1 );
if(dt.getDay() == 0){
console.log(year);
}
}
};
findSunday(2014,2050);// understand Date() better
var guesser = function(){
var number = Math.floor(Math.random() * 10)
if(prompt(number) == number){
alert('right');
}
else{
alert("wrong");
}
};
//guesser(); works but annoying
var dayLeftXmas = function(date){
var xmas = new Date(date.getFullYear(), 11, 25);
var res = xmas - date;
return res
};
//console.log(dayLeftXmas(d)); doesnt work yet learn date better
var mult= function(){
var first = parseInt(document.getElementById("number1").value, 10);
var second = parseInt(document.getElementById("number2").value, 10);
document.getElementById("result").innerHTML = first * second;
};
var divi = function(a,b){
var first = parseInt(document.getElementById("number1").value, 10);
var second = parseInt(document.getElementById("number2").value, 10);
document.getElementById("result").innerHTML = first / second;
};
var doOperation = function(operator){//this solution did not work: said that "operator" was not a function
var first = document.getElementById("number1").text;
var second = document.getElementById("number2").text;
var res = operator(first, second);
document.getElementById("result").innerHTML = res;
};
var tempConvert = function(temp, toType){
if (toType == "f"){
temp = ((temp * 9)/5) + 32;
return temp;
}
else if (toType == "c"){
temp = ((temp - 32) * 5) / 9; //- 32;//the problem is here
return temp;
}
else{
console.log("second param must be 'c' or 'f'");
}
}
console.log(tempConvert(98.6,"c"));
console.log(window.location.href);