Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HW5 #1

Open
wdOq opened this issue Jun 4, 2024 · 1 comment
Open

HW5 #1

wdOq opened this issue Jun 4, 2024 · 1 comment

Comments

@wdOq
Copy link
Owner

wdOq commented Jun 4, 2024

第一題:

  const g = () => {
    const a = 1,
    b = 2,
    c = 3;
    console.log(`a是:${a} b是:${b} c是:${c}`);
  }
g()

第二題:

function print(b){
    if(b==0)
      {
        console.log("此值等於零");
      }
    if(b>0)
      {
        console.log("此值大等於零");
      }
    if(b<0)
      {
        console.log("此值小於零");
      }
    }
print(2);

第三題:

<!DOCTYPE html>
<html lang="en">
<head>
    <style>
        .p {
            color: black;
        }
        @media screen and (min-width: 350px) {
            .p {
                color: blue;
            }
        }
        @media screen and (min-width: 1024px) {
            .p {
                color: red;
            }
        }
    </style>
</head>
<body>
    <p class="p">我的網頁</p>
</body>
</html>

第四題:

<html>
    <body>
        <img Id="pic" src="https://fakeimg.pl/150x130">
        <button Id="on">顯示圖片</button>
        <button Id="off">關閉圖片</button>
    </body>
    <script>
        let pic = document.getElementById('pic');
        let on = document.getElementById('on');
        let off = document.getElementById('off');

        on.addEventListener('click',()=>{
            pic.style.display = 'block';
        })
        off.addEventListener('click',()=>{
            pic.style.display = 'none';
        })
    </script>
</html>

第五題:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h3 Id = "word">我的網頁</h3>
    <button Id = "black">變成黑色</button>
    <button Id = "blue">變成藍色</button>
</body>
<script>
    var word = document.getElementById('word');
    var black = document.getElementById('black');
    var blue = document.getElementById('blue');

    black.addEventListener('click',()=>{
        word.style.color = "black";
    })
    blue.addEventListener('click',()=>{
        word.style.color = "blue";
    })
</script>
</html>

第六題:

function printTree(treeHeight, treeGap) {
    let ans = "\n";
      for(let i = 0;i < treeHeight;i++){
        let dash = ((treeHeight*treeGap)-(treeGap-1)-1)/2-((treeGap/2)*i);
        let stars = treeGap * i + 1;
        ans += '-'.repeat(dash) + '*'.repeat(stars) + '-'.repeat(dash) + '\n';
      }
      //end
    return ans;
  }
  
  const treeHeight = 7;
  const treeGap = 4;
  console.log(printTree(treeHeight, treeGap));

延伸題:

第一題:

const print=(x)=>{
    x%2 == 0 ? console.log("x是2的倍數") : console.log("x不是2的倍數")
}

第二題:

const demo = (arr, index) => {
    arr.splice(index, 1);
    return arr;
  }
  
  console.log(demo(['a', 'b', 'c'], 2));

第三題:

const convertToMinguo = (dateString) => {
    let [year, month, day] = dateString.split(' ')[0].split('-');
    
    year = year - 1911;
  
    const minguoDate = `${year}/${month}/${day}`;
    
    return minguoDate;
  }
  
  const dateString = "2024-05-31 13:43:12";
  console.log(convertToMinguo(dateString)); 

第四題:

const fruits = {
    Banana: {
      num: "一串",
      price: "50"
    },
    Orange: {
      num: "五顆",
      price: "100"
    },
    Apple: {
      num: "3顆",
      price: "50"
    }
  };
  
  Object.keys(fruits).forEach(fruit => {
    const { num, price } = fruits[fruit];
    console.log(`${fruit}${num}${price}元`);
  });

第五題:

for (let i = 1; i <= 9; i++) {
    let row = '';
    for (let j = 1; j <= 9; j++) {
      row += `${i} x ${j} = ${i * j}\t`;
    }
    console.log(row);
  }
  
@dpes8693
Copy link

dpes8693 commented Jun 5, 2024

Markdown可以拆解不同區塊比較好閱讀 以下是範例:

第一題

  const g = () => {
    const a = 1,
    b = 2,
    c = 3;
    console.log(`a是:${a} b是:${b} c是:${c}`);
  }
g()

第二題

function print(b){
    if(b==0)
      {
        console.log("此值等於零");
      }
    if(b>0)
      {
        console.log("此值大等於零");
      }
    if(b<0)
      {
        console.log("此值小於零");
      }
    }
print(2);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants