發表文章

目前顯示的是 11月, 2017的文章

[JavaScript] BMI Calculator

function BMI(name) {     var BMIResult = 0;     function count_BMI(weight, hight) {         var mass = parseInt(weight);         var counter = parseInt(hight) / 100;         BMIResult = mass / (counter * counter);         console.log(name + ' Your BMI is ' + BMIResult.toFixed(2) + '.');         return BMIResult;     }     return count_BMI } var Wesley_BMI = BMI('Wesley'); var Fred_BMI = BMI('Fred'); Wesley_BMI(85, 171); Fred_BMI(66, 180);

[JavaScript] Declare Function( )

=====(1) function showText1(lineNumber1) { console.log("Testing Text: " + lineNumber1) }; showText1('Method 1'); =====(2) var showText2 = new Function('lineNumber2', 'console.log(\'Testing Text: \' + lineNumber2);'); showText2('Method 2'); =====(3) var showText3 = function (lineNumber3) { console.log('Testing Text: ' + lineNumber3); } showText3('Method 3'); =====(4) (function (lineNumber4) { console.log('Testing Text: ' + lineNumber4); } )('Method 4'); =====(5) (function (lineNumber5) { console.log('Testing Text: ' + lineNumber5); } ('Method 5')); =====(6) void function (lineNumber6) {     console.log('Testing Text: ' + lineNumber6); }('Method 6'); =====Note (1)為函數陳述式, 不管放在前或後, 都可以被執行. 其它為函數運算式則需要先建立後才能呼叫. showText7('Method 7'); function showText7(lineNumber7) {     console.log('Testing Text: ' + lineNumber7); }

[JavaScript] Bitwise Operators

圖片

[JavaScript] Statements

=====if else if var today = new Date().getDay(); if (today == 5){   console.log('It is Friday'); } else if (today ==0|| today ==6) {   console.log('No working on the weekend!'); } else {   console.log('working working working!'); } =====switch var today = new Date().getDay(); switch (today){   case 0: console.log('Today it is Sunday'); break;   case 6: console.log('Today it is Saturday'); break;   default: console.log('Today it is ' + today); } or switch (today){   case 0:   case 6: console.log('On the weekend!');break;   default: console.log('Just go back to work!'); } =====for  for (var i = 0; i < 7; i++){   console.log(i); } =====for in var myList = ['A', 2, 'C', 'd', 'x'] for (var i in myList){   console.log(myList[i]); } or var myList = [   {id:'ABC',pw:123},   {id:'DEF',pw:456},   {id:'GHI',pw:789}, ] fo...

[JavaScript] Object and Array in Json

=====Object var myObject = {}; //JSON var myObject = new Object (); //JavaScript key : value Ex. //JSON var myObject {   'name':'Study Note',   'studyDate: '2017,11,22',   }; //In comparison to JavaScript var myObject = new Object(); myObject.name = "Study Note"; myObject.studyDate = "2017/11/22"; =====Array var myArray = []; //JSON var myArray = new Array (); Ex. //JSON var my Array = ['one', 'two', 'three']; //in comparison to JavaScript var myArray = new Array ('one', 'two', 'three');

[Console] My common used commands

=====Terminate Node/Nodemon in console Ctrl + Break =====Nodemon to watch Path  nodemon file.js Ex. C:\Users\Frank\myNode> nodemon index.js [nodemon] 1.12.1 [nodemon] to restart at any time, enter `rs` [nodemon] watching: *.* [nodemon] starting `node index.js` Server has started to listen at port: 8080. =====cd To a direction file =====cd .. To upper direction file =====dir check files name and folders name in direction

[JavaScript] var

圖片
===== String \n 換行 \x00 - \xFF 16bits的字元 \u0000 - \uFFFF 16bits的Unicode字元 也可以用Unicode直接下字元 Ex. \u000A = \n ===== Number 0x或0X開頭的為16進位的數十弓木 0開頭的則是8進位的數字 ===== Boolean var isFalse = false; var isEnd = true; ===== Function function number_add(x, y) { var result = x + y; return result } var num = number_add (1234, 1234); console.log("The result is : " +nub); // the result is : 2468 ====== Object objectName.propertyNam 或objectName['propertyNam'] 讀取變數屬性 objectName.methodName() 或objectName['methodName']() 讀取變數方法 var company = new Object (); company.name = 'WinPOS'; company.url = "www.winpos.com.tw"; company.establishYear = new Date().setFullYear(1997,8,1); ===== Array var company = new Array(); company.name = 'Ro Company'; company.url = 'www.RoCompany.com'; company.establishment = new Date().setFullYear(2017,11,22); company[0]...