|
@@ -62,14 +62,16 @@ function sum3(num1, num2, num3) {
|
|
|
// return num;
|
|
|
// }
|
|
|
|
|
|
-function intRandom(min, max) {
|
|
|
+function intRandom(min, max=0) {
|
|
|
|
|
|
- if(max != prompt) {
|
|
|
- max = min;
|
|
|
- min = 0;
|
|
|
+ let num;
|
|
|
+
|
|
|
+ if(max === 0) {
|
|
|
+ num = max + Math.random() * (min - max);
|
|
|
+ } else {
|
|
|
+ num = min + Math.random() * (max - min);
|
|
|
}
|
|
|
|
|
|
- let num = min - 0.5 + Math.random() * (max - min + 1);
|
|
|
return Math.round(num);
|
|
|
}
|
|
|
|
|
@@ -131,19 +133,19 @@ function sum() {
|
|
|
// --------------------------------------------Union declarative--------------------------------------------------------------
|
|
|
|
|
|
let taskNames = {
|
|
|
- "a": a,
|
|
|
- "cube": cube,
|
|
|
- "avg2": avg2, // Doesn't work for now
|
|
|
- "sum3": sum3,
|
|
|
- "intrandom": intRandom,
|
|
|
- "greetAll": greetingsAll,
|
|
|
- "sum": sum
|
|
|
+ "a": () => a("Hello Stranger"),
|
|
|
+ "cube": () => alert(cube(3)),
|
|
|
+ "avg2": () => alert(avg2(+prompt("Enter first digit"), +prompt("Enter second digit"))),
|
|
|
+ "sum3": () => alert(sum3(+prompt("Enter first digit"), +prompt("Enter second digit"), +prompt("Enter third digit"))),
|
|
|
+ "intrandom": () => alert(intRandom(+prompt("Enter Min value"), +prompt("Enter Max value"))),
|
|
|
+ "greetAll": () => greetingsAll("Sam", "Dean", "Jonathan"),
|
|
|
+ "sum": () => alert(sum(10, 25, 33, 46, 56))
|
|
|
}
|
|
|
|
|
|
let taskToStart = prompt("Введите название задания");
|
|
|
|
|
|
for(let key in taskNames) {
|
|
|
if(key === taskToStart) {
|
|
|
- alert(key);
|
|
|
+ alert(taskNames[key]());
|
|
|
}
|
|
|
}
|