1.數(shù)字轉換為字母
var ch = String.fromCodePoint( parseInt(t) + 64) //大寫
ch = String.fromCodePoint( parseInt(t) + 96 ) //小寫
2.== & ===
https://www.zhihu.com/question/20348948
2.數(shù)學運算
parseInt(4/3) //取整
Math.ceil(4/3) //向上取整
Math.round(4/3) //四舍五入
Math.floor(4/3) //向下取整
Math函數(shù)的一些其他方法
abs(x) //絕對值
exp(x) //e的指數(shù)
max(x,y)
min(x,y)
pow(x,y) //x的y次冪
random() //0-1之間的隨機數(shù)
round(x) //四舍五入為一個最接近的整數(shù)
valueOf() //返回Math對象的原始值
3.輸出
- 控制臺輸出console.log()
- 對話框輸入:a = prompt(1+2=?)?
對話框輸入的結果即為a的值
4.增強for循環(huán)
- for in(i為數(shù)組下標)
var stu_scores = {'楊璐':131,
'王雪':131,
'韓林霖':127,
'沙龍逸':123,
'李鑒學':126,
'韓雨萌':129,
'劉帥':116,
'康惠雯':114,
'劉鈺婷':115};
var stu_names = ['楊璐',
'王雪',
'韓林霖',
'沙龍逸',
'李鑒學',
'韓雨萌',
'劉帥',
'康惠雯',
'劉鈺婷'];
var scores = [];
var highest_score = 0;
//使用for循環(huán)取出成績數(shù)組,打印所有成績,找到做高分
for(var i in stu_names){
var score = stu_scores[stu_names[i]]
scores.push(score)
if(score > highest_score)
highest_score = score
}
//獲取所有學生的分數(shù)(只包含學生分數(shù)不包含學生姓名)存到scores中
var highest_score = scores[0];
//使用for循環(huán)找出學生成績的最高分
console.log('學生成績的最高分:'+highest_score);
- forEach
stu_names.forEach(name =>{
var score = stu_scores[name]
scores.push(score)
if(score > highest_score)
highest_score = score
})
- forEach
stu_names.forEach(function(name){
var score = stu_scores[name]
scores.push(score)
if(score > highest_score)
highest_score = score
})