JS Classic Case-arrow function hit the stars, palindrome number judgment

Source: Internet
Author: User

//user input number, according to the user's choice to print the stars//just playing the star function.Let Chooseone = line ={Let strspace= ""; Let Strstar= ""; //this layer for loop controls the number of rows of stars     for(Let I=1; i<=line; i++)    {        //the layer for loop controls the number of spaces         for(Let J=1; j<=line-i; J + +) {Strspace= Strspace + ""; }        //this layer for loop controls the number of stars         for(Let k=1; k<=2*i-1; k++) {Strstar= Strstar + ' * '; } console.log (Strspace+ Strstar);//print spaces and stars        //Reset the space and star stringsStrspace = ""; Strstar= ""; }}//hit the stars upside downLet Choosetwo = line ={Let strspace= ""; Let Strstar= ""; //this layer for loop controls the number of rows of stars     for(Let I=1; i<=line; i++)    {        //the layer for loop controls the number of spacesStrspace + = "";//Print space before printing a space specifically, in order to facilitate the printing of diamonds in the back         for(Let J=1; j<=i-1; J + +) {Strspace= Strspace + ""; }        //this layer for loop controls the number of stars         for(Let k=1;k<=line*2-(2*i-1); k++) {Strstar= Strstar + ' * '; } console.log (Strspace+ Strstar);//print spaces and stars        //Reset the space and star stringsStrspace = ""; Strstar= ""; }}//Hollow TrianglesLet Choosethree = line ={Let strspace= ""; Let Strstar= ""; //this layer for loop controls the number of rows of stars     for(Let i=1;i<=line;i++)    {        //the layer for loop controls the number of spaces         for(Let J=1; j<=line-i; J + +) {Strspace= Strspace + ""; }        //this layer for loop controls the number of stars         for(Let k=1; k<=2*i-1; k++)        {            //if it's the first line, or the last line or the first star or the last star            if(i==1 | | i==line | | k==1 | | k==2*i-1) {Strstar= Strstar + ' * ';//concatenation of strings inside *            }            Else{Strstar= Strstar + ";//concatenation of strings inside "'}} console.log (Strspace+ Strstar);//print spaces and stars        //Reset the space and star stringsStrspace = ""; Strstar= ""; }}//DiamondLet Choosefour = line ={Let top= parseint ((line+1)/2);//number of rows of the star to let bottom = line-top;//number of rows of the inverted star    //first, I'm hitting the stars.Chooseone (top); //Next, hit the stars upside down.choosetwo (bottom);}"Use Strict"Let readline= Require ("Readline-sync"); Console.log ("Please enter the graphic you want to print: 1. Playing the Stars 2. Hit the stars upside down 3. Hollow Triangle 4. Diamond (Odd)"); let choose= parseint (Readline.question ("")); Console.log ("Please enter the number of lines of stars:").= parseint (Readline.question (""));Switch(choose) { Case1: Chooseone (line);  Break;  Case2: Choosetwo (line);  Break;  Case3: Choosethree (line);  Break;  Case4: Choosefour (line);  Break; default: Console.log ("Your input is wrong");}

//Judging whether it is a palindrome numberLet ReadLine = require ("Readline-sync"); Console.log ("Please enter the number of palindrome you want to judge:"); let Oldnum= parseint (Readline.question (""));//number of 1234 to hold user inputLet newnum = 0;//used to hold the inverted number//assigns the number of user input backwards to newnum for(Let temp = oldnum;temp!=0; temp = parseint (TEMP/10))//temp 0{newnum= newnum*10 + temp%10;//4321 Why multiply it by 10? }if(Newnum = =oldnum) {Console.log ("is a palindrome number");}Else{Console.log ("Not a palindrome number.");}

JS Classic Case-arrow function hit the stars, palindrome number judgment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.