確認視窗,會傳回true或false值
alert("your message")
提醒視窗,沒有回傳值
var lastName = "your last name"
定義變數的方法
"string".length
傳回string的長度
- String Method
"original string".replace("word to be replaced", "replacement word");
換string裡的字
"hello".substring(0,2)
取出string裡第0字開始後2字
"hello".toUpperCase()
"hello".toLowerCase()
console.log("message")
prompt("message") 跳出可輸入視窗,回傳user輸入值(string)
for ( initialization; condition;increment ) {
// code to run each iteration
}
Project:FizzBuzz
// for the numbers 1 through 100,
for (i=1; i<=100; i++) {
if (i%3===0&&i%5===0){
console.log("FizzBuzz");
}
// if the number is divisible by 3, write "Fizz"
else if ( i % 3 === 0 ) {
console.log("Fizz");
}
// if the number is divisible by 5, write "Buzz"
else if ( i % 5 === 0 ) {
console.log("Buzz");
}
// otherwise, write just the number
else {
console.log(i);
}
}