Question #26590
I am a beginner and i want to know how to execute the below pattern in through javascript,
*
**
***
****
*****
and
*****
***
*
*
***
*****
1
Expert's answer
2013-03-19T10:35:27-0400
You can generate required patterns in such way: -Pattern             *            **            ***            ****             JavaScript:                         document.write('Pattern#1</br>');                        varcount=10;//maximum number of * symbol                        varpattern='';                        for(var i=1;i<=count;i++) {                                   document.write((pattern+='*')+'</br>');//changepattern and write it to document                        } -Pattern             *****            ***             *             *            ***            *****                          Javascript:                         document.write('Pattern#2</br>');                        varpattern='*****';                        varaddIt='';                        varaddItSymb=' ';//symbol to add                         /*                        *****                        ***                         *                        */                        while((2*addIt.length)<pattern.length) {                                   document.write(addIt+pattern.substring(0,pattern.length-2*addIt.length)+addIt+'</br>');                                   addIt+=addItSymb;                        }                        /*                         *                        ***                        *****                        */                        while(addIt.length!=0) {                                   addIt=addIt.substring(0,addIt.length-1);                                   document.write(addIt+pattern.substring(0,pattern.length-2*addIt.length)+addIt+'</br>');                        } To view results you can use such HTML document             <html>            <head>                        <scripttype="text/javascript">                                   <!--INSERT JAVASCRIPT HERE -->                        </script>            </head>                        <body>                        </body>            </html>

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS