60 526
Assignments Done
97,8%
Successfully Done
In April 2018

Answer to Question #26590 in AJAX | JavaScript | HTML | PHP for Anshu

Question #26590
I am a beginner and i want to know how to execute the below pattern in through javascript,
*
**
***
****
*****
and
*****
***
*
*
***
*****
Expert's answer
You can generate required patterns in such way:





-Pattern





*


**


***


****





JavaScript:





document.write('Pattern
#1</br>');


var
count=10;//maximum number of * symbol


var
pattern='';


for
(var i=1;i<=count;i++) {


document.write((pattern+='*')+'</br>');//change
pattern and write it to document


}





-Pattern





*****


***


*


*


***


*****





Javascript:





document.write('Pattern
#2</br>');


var
pattern='*****';


var
addIt='';


var
addItSymb=' ';//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>


<script
type="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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions