Write a Node.js program that outputs a random square to the console up to 10.
basically, create a quick function to get a random number and then display a asterisk length and width of that random number
I use my terminal to run the javascript file
For example, if the random number is 6, then the output would be a 6x6 box of " * ":
* * * * * *
* * * * * *
* * * * * *
* * * * * *
* * * * * *
* * * * * *
Required Code -->
<html>
<head>
<title>JavaScript Number Patterns</title>
<script type="text/javascript">
var no=QuickFunction(); //declare integer variable no and call
function QuickFunction
for(var m=1;m<=no;m++){ //for loop for m starts from m=1 to
m<=no for rows
for(var n=1;n<=no;n++){ //for loop for n starts from n=1 to
n<=no for columns
document.write("* "); //print * and a space
}
document.write("<br />"); //change the line after each
row
}
function QuickFunction() { //function named
QuickFunction()
var number=prompt("Number: "); //declare a variable and ask user
for an integer value
if(number<=10 || number>0){ //if number is between 1 to
10
return number; //returns the value of number
}
}
</script>
</head>
<body></body>
</html>
Get Answers For Free
Most questions answered within 1 hours.