好玩的~
1怜瞒、倒計(jì)時(shí)效果
代碼
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover">
<title>Page Title</title>
</head>
<body>
<div class="wrap">
<div class="over">本場距離結(jié)束還剩</div>
<div class="time">
<span class="hour"></span>:
<span class="minute"></span>:
<span class="second"></span>
</div>
</div>
<script>
let hour = document.querySelector('.hour');
let minute = document.querySelector('.minute');
let second = document.querySelector('.second');
let inputTime = +new Date('2022-5-1 24:00:00');
function countDown() {
let nowTime = +new Date();
let times = (inputTime - nowTime) / 1000;
let h = parseInt(times / 60 / 60 % 24);
h = h < 10 ? '0' + h : h;
hour.innerHTML = h;
let m = parseInt(times / 60 % 60);
m = m < 10 ? '0' + m : m;
minute.innerHTML = m;
let s = parseInt(times % 60);
s = s < 10 ? '0' + s : s;
second.innerHTML = s;
}
setInterval(countDown, 1000);
</script>
</body>
</html>
題目練習(xí)
https://www.nowcoder.com/exam/oj/ta?page=1&tpId=290&type=290
1监婶、小飛機(jī)
console.log(" ** "+"\n"+" ** "+"\n"+"************"+"\n"+"************"+"\n"+" * * "+"\n"+" * * ");
涉及:console.log()览芳,字符串拼接,換行 \n
應(yīng)用場景:
a.console.log()打印排查問題洲押,讀懂代碼邏輯
eg:console.log('數(shù)據(jù)接口data',data)
debugger
練習(xí)
輸入描述:
輸入一個(gè)浮點(diǎn)數(shù)
輸出描述:
輸出一個(gè)浮點(diǎn)數(shù)武花,保留三位小數(shù)
console.log(parseFloat(readline()).toFixed(3))
let str = readline();
function f1(str){
const str1 = str.toString()
const idx = str1.indexOf('.')
let first = parseFloat(str1.substring(0,idx+4))
const char1 = parseFloat(str1.charAt(idx+4))
if(char1>4){
first = ((first*1000 + 1)/1000).toFixed(3)
}
console.log(first)
}
f1(str)
2.字符串反轉(zhuǎn)
let str='123456';
str.split('').reduceRight((prev,curr)=>prev+curr)
先轉(zhuǎn)換為數(shù)組
str.split('').reverse().join('')
3.數(shù)組去重
return Array.from(new Set(array))
Array.from
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/from
new Set()
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Set