안효원 안효원 2022-02-08
Until num5 class
@38f17ef6f3b94ca1e61eb9fb63416d238fc6ab4c
.vscode/launch.json
--- .vscode/launch.json
+++ .vscode/launch.json
@@ -1,15 +1,0 @@
-{
-    // Use IntelliSense to learn about possible attributes.
-    // Hover to view descriptions of existing attributes.
-    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
-    "version": "0.2.0",
-    "configurations": [
-        {
-            "type": "pwa-chrome",
-            "request": "launch",
-            "name": "Launch Chrome against localhost",
-            "url": "http://localhost:8080",
-            "webRoot": "${workspaceFolder}"
-        }
-    ]
-}
(No newline at end of file)
al01/2.js
--- al01/2.js
+++ al01/2.js
@@ -1,13 +1,16 @@
 //길이가 다른 3개의 막대로 삼각형을 만들 수 있는지 여부
 
 function triangle(a, b, c){
-    let result;
+    let result = "NO";
 
-    if(a+b>c && a+c>b && b+c>a){
-        result = "YES";
-    }else{
-        result ="NO";
+    if(a>0 && b>0 && c>0){
+        if(a+b>c && a+c>b && b+c>a){
+            result = "YES";
+        }
     }
+    
+    
+
 
     return result;
 }
al01/3.js
--- al01/3.js
+++ al01/3.js
@@ -1,7 +1,16 @@
 //1개씩 줄 때 학생 N명이 있을 때 필요한 연필의 다스 수
 
+// function das(a){
+//     return Math.ceil(a/12);
+// }
+
 function das(a){
-    return Math.ceil(a/12);
+    let answer;
+
+    // answer = Math.ceil(a/12);
+    answer = (a%12===0)?a/12:parseInt(a/12)+1;
+
+    return answer;
 }
 
 console.log(das(25));
al01/4.js
--- al01/4.js
+++ al01/4.js
@@ -2,8 +2,14 @@
 
 function sum(a){
     let sum = 0;
-    for(let i = 1; i <= a; i++){
-        sum = sum + i;
+    // for(let i = 1; i <= a; i++){
+    //     sum += i;
+    // }
+
+    let i = 1;
+    while(i<=a){
+        sum += i;
+        i++;
     }
 
     return sum;
@@ -11,4 +17,5 @@
 }
 
 console.log(sum(6));
-console.log(sum(10));
(No newline at end of file)
+console.log(sum(10));
+console.log(sum(100));
(No newline at end of file)
al01/5.js
--- al01/5.js
+++ al01/5.js
@@ -1,15 +1,19 @@
 //7개의 수 중 가장 작은 것
 
-function min(a, b, c, d, e, f, g){
-    let arr = [a, b, c, d, e, f, g];
-    let max = arr[0];
+function min(arr){
     let min = arr[0];
-    for(let i = 1; i<=7; i++){
-        if(min>arr[i]){
-            min = arr[i];
-        }
+
+    for(let i = 1; i<=arr.length; i++){
+        //else-if
+        // if(min>arr[i]){
+        //     min = arr[i];
+        // }
+
+        //삼항연산자
+        min = min>arr[i] ? min=arr[i] : min;
+
     }
-    console.log(min);
+    return min;
 }
 
-min(1, 3, 7, 11, 2, 15, 17);
(No newline at end of file)
+console.log(min([1, 3, 7, 11, 2, 15, -20]));
(No newline at end of file)
Add a comment
List