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>
Comments
Leave a comment