Jelajahi Sumber

tasks in till intRandom inclued done

miskson 3 tahun lalu
induk
melakukan
23246a8644
2 mengubah file dengan 50 tambahan dan 0 penghapusan
  1. 13 0
      hw6/index.html
  2. 37 0
      hw6/script.js

+ 13 - 0
hw6/index.html

@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Homework6</title>
+</head>
+<body>
+    <h1>Homework 6</h1>
+    <script src="./script.js"></script>
+</body>
+</html>

+ 37 - 0
hw6/script.js

@@ -0,0 +1,37 @@
+console.log('hello')
+// a
+function a(msg) {
+   return alert(msg)
+}
+//a('hello')
+
+// cube 
+function cube(num) {
+    return num**3
+}
+console.log(cube(3))
+
+//avg2
+function avg2(num1, num2) {
+    return (num1 + num2) / 2
+}
+console.log(avg2(1,2))
+console.log(avg2(10, 5))
+
+//sum3
+function sum3(num1, num2, num3=0) {
+    return num1 + num2 + num3
+}
+
+console.log(sum3(1,2))
+console.log(sum3(1,2,3))
+console.log(sum3(5,10,100500))
+
+//intRandom
+function intRandom(min, max) {
+    min = Math.ceil(min)
+    max = Math.floor(max)
+    res = (Math.random() * (max - min) + min) <= 0? Math.ceil(Math.random() * (max - min) + min) : Math.floor(Math.random() * (max+1 - min) + min)
+    return res === -0? 0 : res
+}
+console.log(intRandom(-4, 5))