标签:strong parse 创建文件 pac rip bsp int pre oba
在 JavaScript 中,为不同的决定来执行不同的动作,我们可使用以下条件语句:
多重判断(if..else嵌套语句)
if(条件1) { 条件1成立时执行的代码} else if(条件2) { 条件2成立时执行的代码} ... else if(条件n) { 条件n成立时执行的代码} else { 条件1、2至n不成立时执行的代码}
案例一:
// 分别输入姓名,身高,体重,性别,判断身体状况。(体重按公斤计算)
计算公式man=体重-(身高-100),woman=体重-(身高-110);大于3为超重,小于-3为偏瘦,其余为正常
var readline=require(‘readline-sync‘) console.log(‘请输入姓名‘) var name=readline.question(); console.log(‘请输入身高‘) var height=parseInt(readline.question()); console.log(‘请输入体重‘) var weight=parseInt(readline.question()); console.log(‘请输入性别(man/woman)‘) var sex=readline.question(); if(sex==‘man‘){ var manhealth=weight-(height-100); if(manhealth>3){ console.log(‘超重‘) } else if(manhealth<3){ console.log(‘偏瘦‘) } else{ console.log(‘健康‘) } } if(sex==‘woman‘){ var health=parseInt(weight-(height-110)); if(health>3){ console.log(‘超重‘) } else if(health<3){ console.log(‘偏瘦‘) } else{ console.log(‘健康‘) } }
当有很多种选项的时候,switch比if else使用更方便。
switch(表达式) { case值1: 执行代码块 1 break; case值2: 执行代码块 2 break; ... case值n: 执行代码块 n break; default: 与 case值1 、 case值2...case值n 不同时执行的代码
break;循环就会结束,不会输出后面循环的内容
continue本次循环将被跳过,而后续的循环则不会受到影响
安装 node步骤:
1.node 安装
直接点一下就OK
2.修改镜像地址(下载模块)
npm conflig set registry=https://registry.npm.taobao.org
(学校局域网)服务器镜像:在命令行中敲入
npm config set registry=http://192.168.8.10:7001
3.查看是否安装成功:node -v
4.创建文件夹,cmd中进入文件
输入npm init 初始化文件,成功后会创建出一个package.json文件
5.在文件中创建一个***.js文件,里面写 console.log(‘111111‘)
6.用cmd打开,dos命令进入文件夹,运行nodee *** 或 node ***.js
安装输入模块:npm install readline-sync
下载成功会自动生成一个 node_modules 文件夹
JS入门基础(if else 与 switch case / node安装)
标签:strong parse 创建文件 pac rip bsp int pre oba
原文地址:http://www.cnblogs.com/lingzi940924/p/6859007.html