当前位置:网站首页>JS的初步语法
JS的初步语法
2022-06-30 00:00:00 【山岚~】

两种常见代码的引入方式;


如果js写在head中, 相当于是全局变量,
ctrl tab切换文件;
token就是令牌,你带着令牌接口才会承认。
let buf = "";
process.stdin.on("readable", function(){
let chunk = process.stdin.read();
if(chunk) buf+= chunk.toString()
;})
process.stdin.on("end", function(){
// let [x,y] = buf.split(' ').map(x => {return parseInt(x)});
let [x,y] = buf.split(' ').map(function(x){
return parseInt(x)});
let price = [4.00,4.50,5.00,2.00,1.50];
let res = y * price[x - 1];
console.log(`Total: R$ ${
res.toFixed(2)}`);
})
注意看注释的哪一行, 二者都可以运行, 是等价的;
if else语句
let buf = "";
process.stdin.on("readable", function(){
let chunk = process.stdin.read();
if (chunk) buf += chunk.toString();
})
process.stdin.on("end", function(){
// let a = buf.split('').map(x => {return x});
//上面的这种方法是错误的;
let a = parseFloat(buf);
if(a >= 0 && a <= 25){
console.log("Intervalo [0,25]");
}
else if (a>25 && a <= 50)
{
console.log("Intervalo (25,50]");
}
else if( a > 50 && a <= 75)
{
console.log("Intervalo (50,75]");
}
else if (a > 75 && a <= 100)
{
console.log("Intervalo (75,100]");
}
else
{
console.log("Fora de intervalo");
}
})
let buf = "";
process.stdin.on("readable", function() {
let chunk = process.stdin.read();
if (chunk) buf += chunk.toString();
});
process.stdin.on("end", function() {
let [a, b, c] = buf.split('\n');
if (a === "vertebrado") {
if (b === "ave") {
if (c === "carnivoro") {
console.log("aguia");
} else {
console.log("pomba");
}
} else {
if (c === "onivoro") {
console.log("homem");
} else {
console.log("vaca");
}
}
} else {
if (b === "inseto") {
if (c === "hematofago") {
console.log("pulga");
} else {
console.log("lagarta");
}
} else {
if (c === "hematofago") {
console.log("sanguessuga");
} else {
console.log("minhoca");
}
}
}
});
上面的部分, 注意split()中的部分是根据’\n’;不是空格;
- 循环
eg721递增序列:
let x;//记得有需要初始化
let buf = '';
process.stdin.on("readable", function(){
let chunk = process.stdin.read();
if (chunk) buf += chunk.toString();
});
process.stdin.on("end", function(){
let xs = buf.split('\n').map(function(x){
return parseInt(x);
});
for (let x of xs){
if (x === 0) break;
let line = "";
for (let i = 1; i <= x; i ++)
line += `${
i} `; //因为console.log()存在回车 故我们先拼接字符串然后再回车
console.log(line);
}
});
因为console.log()存在回车 故我们先拼接字符串然后再回车
let n = parseInt(buf);
// let m = n/2;
let m = parseInt(n / 2);
注意m这里是不一样的,必须通过
let m = parseInt(n / 2);
这种, 而不能直接等于n/2;
- 数组

process.stdin.on("end", function(){
let lines = buf.split('\n');
let n = parseInt(lines[0]);
let op = lines[1];
let d = [];
for(let i = 0 ; i < 12 ; i ++)
{
d.push(lines[i+2].split(' ').map(x => {
return parseFloat(x)}))
}
let sum = 0;
for(let i = 0 ; i <12 ; i ++ )
sum+=d[n][i];
if(op==='M') sum/=12;
console.log(`${
sum.toFixed(1)}`);
})
好好体会分块的思想吧;
- 函数
let buf = "";
process.stdin.on("readable", function() {
let chunk = process.stdin.read();
if (chunk) buf += chunk.toString();
});
let max = (x, y) => {
return x > y ? x : y;
};
process.stdin.on("end", function() {
let [x, y] = buf.split(' ').map(x => {
return parseInt(x)});
console.log(max(x, y));
});
边栏推荐
- [rust weekly library] Tokei - a utility for statistics of code lines and other information
- label问题排查:打不开标注好的图像
- Stack space of JVM
- New titanium cloud service won the "2022 love analysis · panoramic report of it operation and maintenance manufacturers" cloud management platform CMP representative manufacturer
- 克隆无向图[bfs访问每条边而不止节点]
- 6.28日刷题题解
- Set up security groups, record domain names, and apply for SSL certificates
- QT learning 07 coordinate system in QT
- What is IGMP? What is the difference between IGMP and ICMP?
- How long will it take to open a mobile account? In addition, is it safe to open a mobile account?
猜你喜欢

Zhongang Mining: Fluorite helps the construction and development of lithium battery in fluorine industry

Golang6 reflection

Cartoon security HIDS, EDR, NDR, XDR

Mysql:sql overview and database system introduction | dark horse programmer

ThinkPad VMware installation virtual machine: this host supports Intel VT-x, but Intel VT-x is disabled (problem resolution)

QT learning 03 birth and essence of QT

数莓派 4怎么样?可能的玩法有哪些?

Getting started with qpainter: drawing the chess interface

【微信小程序】认识小程序项目的基本组成结构

Buffer flow exercise
随机推荐
Solr basic operation 11
8软件工程环境
请指教同花顺软件究竟是什么?究竟网上开户是否安全么?
这次的PMP考试(6月25日),有人欢喜有人忧,原因就在这...
QT learning 01 GUI program principle analysis
ThinkPad VMware installation virtual machine: this host supports Intel VT-x, but Intel VT-x is disabled (problem resolution)
Label Troubleshooting: unable to open the marked image
手机开户后多久才能通过?另外,手机开户安全么?
Which securities company should I choose to open an account online? Also, is it safe to open an account online?
shell-运算符
Siemens low code platform connects MySQL through database connector to realize addition, deletion, modification and query
How long will it take to open a mobile account? In addition, is it safe to open a mobile account?
Copy linked list with random pointer [space for time --hash record]
Solr基础操作13
Sword finger offer 13 Range of motion of robot
我想知道今天还可以开户么?另外想问,现在在线开户安全么?
Solr基础操作7
Table responsive layout tips for super nice
Root cause of glideexception: failed decodepath{directbytebuffer- > gifdrawable- > drawable}
FPGA Development (2) -- IIC communication