顯示具有 CCy_PJ 標籤的文章。 顯示所有文章
顯示具有 CCy_PJ 標籤的文章。 顯示所有文章

2020年7月8日 星期三

Message Mixer

先建立一個有名子的空物件,把我想打包的函數都作為他的性質存起來。
如果函數都是 function Name(){*}這副德行,我該怎麼做 ?
我的作法是就是 Name: function(){*},看過Hint就知道我錯了。

函數當成Object.PropertyName ( === function's Name) = Anonymous Function
MessageMixer = {};
Message.Name = function(){*}

sentence.split(" ").join(character + " ")
const character = '&';
const sentence = "My name is Chung Hao Yang.";
sentence.split(" ") 
Array ["My", "name", "is", "Chung", "Hao", "Yang."]
按照空白,拆解 string 成 array

.join() 回傳 拼接成的字串,.join(character + " ") = "&_",底線代表空白。

console.log(sentence.split(" ").join(character + " "));
=> "My&_name&_ is&_ Chung&_Hao&_Yang."

module.exports 和 export default 之間的差異
module.exports = ObjectName;
let VariableName = require('Path')

export default ObjectName;
import ObjectName from 'Path'

Node.js 支援 module.exports 和 require(),ES6 支援 export default / import  from,後者可讀性及彈性高。


現在遇到一個問題
let availableAirplanes = [ {name: 'AeroJet', fuelCapacity: 800, availableStaff: ['pilots', 'flightAttendants', 'engineers', 'medicalAssistance', 'sensorOperators'], maxSpeed: 1200, minSpeed: 300 }, {name: 'SkyJet', fuelCapacity: 500, availableStaff: ['pilots', 'flightAttendants'], maxSpeed: 800, minSpeed: 200 } ]; function displayFuelCapacity() { availableAirplanes.forEach(function(element) { console.log('Fuel Capacity of ' + element.name + ': ' + element.fuelCapacity); }); }
element.name 為什麼不能改成 element["name"] ?
可以,是我剛剛打錯成 element.[name] ,正確是 element["name"]

displayFuelCapacity();

================================

console.log(MessageMixer.palindrome());
  console.log(MessageMixer.pigLatin()); //我怎麼知道我要傳什麼參數




2020年7月7日 星期二

Build A Library

reduce 會執行使用者提供的函數,稱作 reducer function ,最後回傳一個值。
至於是什麼值,就看你的 reducer function如何寫了。

子類別繼承父類別,但 super(argumentName)    引用 父類別的建構子,要包覆在 子類別的建構子裏頭。

arrayName.push(element1,element2,....)    雖然可以添加多個元素進去 array裏頭,但在今天的例子裏頭,卻受限於 addRating(ratings)內的 array.push(ratings),固然一次只能添加一個元素進去。

我在class 裏頭犯最多的錯誤就是沒有加this。

以下為什麼出問題?
let sum = 0;
const reducer = (acc, cur) => { acc + cur }; <=== 這裡我忘了加 return 
const reducer = (acc, cur) => { return acc + cur };
arrayName.reduce(reducer, sum);
 

2020年7月5日 星期日

Piano_Keys

 <div></div> 是區塊元素 ( style.default_display = 'block')
<section></section>也是區塊元素
div只用來做CSS花樣, section 除了花樣之外,兼有文章、論文以上具備小標題的段落。


2020年7月4日 星期六

Chore Door!

gameOver('win') 

const gameOver = (status) => {
    if (status === 'win' ){
        startButton.inner = 'Good luck!' ;
    }
}

以上無法 hoisting,跑不出結果。

但是  gameOver('win') 是包覆在其他 "函數體內"是OKay的。

_________________________________________________

const numClosedDoors = 3;    <------改成 let numClosedDoors = 3;

const playDoor = ( ) => {
    numClosedDoors --;    <--------------- const numClosedDoors 常數無法 --
    if (numClosedDoors === 0) {
        gameOver('win')
    }
}