In JavaScript, to perform different actions for different decisions, we can use the following conditional statements:
- If statement-use this statement to execute code only if the specified condition is true
- If...else Statement-executes code when the condition is true and executes other code when the condition is false
- If...else If....else Statement-Use this statement to select one of several code blocks to execute
- Switch statement-Use this statement to select one of several code blocks to execute
Multiple judgments (if.. else nested statements)
if (condition 1) {condition 10% code to execute immediately} Else if (condition 2) {condition 20% code executed immediately} ... Else if (condition N) {The code executed when condition n was established} Else {conditions 1, 2 to n are not immediately executed code}
Case one:
Enter your name, height, weight, gender, and determine your physical condition, respectively. (weight per kilogram)
Calculation Formula man= weight-(height -100), woman= weight-(height-110); More than 3 is overweight, less than 3 is thin, the rest is normal
varReadline=require ('Readline-sync') Console.log ('Please enter your name')varName=readline.question (); Console.log ('Please enter your height')varheight=parseint (Readline.question ()); Console.log ('Please enter your weight')varweight=parseint (Readline.question ()); Console.log ('Please enter gender (Man/woman)')varsex=readline.question ();if(sex=='Mans'){ varmanhealth=weight-(height- -); if(manhealth>3) {Console.log ('Overweight') } Else if(manhealth<3) {Console.log ('Partial Thin') } Else{Console.log ('Health') }}if(sex=='woman'){ varHealth=parseint (weight-(height- the)); if(health>3) {Console.log ('Overweight') } Else if(health<3) {Console.log ('Partial Thin') } Else{Console.log ('Health') }}
Switch is more convenient than if else when there are a number of options.
Switch (expression) { case value 1:1break, case value 2: 2 break ;... case value N: execute code block n break; default : code executed when the case value is 1, 2...case value n
break; The loop will end without outputting the contents of the back loop
Continue this cycle will be skipped, and subsequent loops will not be affected
To install the node step:
1.node Installation
Just a little bit, OK.
2. Modify the image address (download module)
NPM Conflig Set registry=https://registry.npm.taobao.org
(School LAN) server mirroring: Typing in the command line
NPM Config set registry=http://192.168.8.10:7001
3. See if the installation was successful: Node-v
4. Create folder, cmd to enter file
Enter NPM init initialization file and a Package.json file will be created after success
5. Create a ***.js file in the file that writes Console.log (' 111111 ')
6. Open with CMD, DOS command into folder, run NodeE * * * or node ***.js
Installing the Input module: NPM Install Readline-sync
Successful download will automatically generate a Node_modules folder
JS Getting Started basics (if else and switch Case/node installation)