001)
var numOfShoes = '2';
var numOfSocks = 4;
var totalItems1 = numOfShoes + numOfSocks;
var totalItems2 = +numOfShoes + numOfSocks;
var totalItems3 = Number(numOfShoes) + numOfSocks;
document.write(totalItems1+','+totalItems2+','+totalItems3);
24,6,6
002)
message = message + ' ' + name;
->message += ' ' + name;
003)
properties[properties.length] = 'bold';
->properties.push('bold');
properties.push('bold', 'italic', 'underlined'); // multi
properties.unshift('bold'); // beginning of an array
var p = [0,1,2,3];
var removedItem = p.pop(); // remove the item from the end of the array
= [0,1,2]
var p = [0,1,2,3];
var removedItem = p.shift(); // remove the item from the beginning.
= [1,2,3]
004)
document.body.style.backgroundColor='green';
005)
var luckyNumber = prompt('What is your lucky number?','');
luckyNumber = parseInt(luckyNumber); // parseInt() converts the value to an integer
// if input isn't a number then it will provide a special
// JavaScript value, NaN (¡°not a number.¡±)
if (isNaN(luckyNumber)) {
luckyNumber = prompt('Please, tell me your lucky number.','');
}
006)
function printToday() {
var today = new Date();
document.write(today.toDateString()); //Sun May 11 2013
}
007)
var TAX = .08; // 8% sales tax
function calculateTotal(quantity, price) {
var total = quantity * price * (1 + TAX);
var formattedTotal = total.toFixed(3); //¼Ò¼öÁ¡ 3ÀÚ¸®
return formattedTotal; // returns the value
}
body
document.write('Total: $' + calculateTotal(2, 16.95));
008)
document.getElementById('banner') // <div id=¡°banner¡±>
document.getElementsByTagName(¡®a¡¯) //selects all anchor tags on a page
|
|