- 4

How to print pattern using # and * alternatively using JavaScript?

#*#*#*#*#* *#*#*#*#*# #*#*#*#*#* *#*#*#*#*#

3rd Jun 2021, 4:20 AM
Sneha Bharti
7 Answers
3rd Jun 2021, 4:22 AM
A͢J
A͢J - avatar
+ 1
Sneha Bharti How did you try in python?
3rd Jun 2021, 4:49 AM
A͢J
A͢J - avatar
+ 1
Sneha Bharti See in JavaScript. Not much difference in logic. I have just taken a variable called str and concated each character and then printed after each iteration of 1st loop. I didn't print each character inside console.log because it print with new line. It's a default behaviour. https://code.sololearn.com/Wtsw9bIh7v69/?ref=app
3rd Jun 2021, 6:07 AM
A͢J
A͢J - avatar
0
n=int(input()) for r in range(n): for i in range(n): if(r%2==0): if(i%2==0): print("#",end=" ") else: print("*",end=" ") else: if(i%2==0): print("*",end=" ") else: print("#",end=" ") print("\n")
3rd Jun 2021, 4:57 AM
Sneha Bharti
0
according to your profil, you have done the html and css courses, and more than 50% of the js course: so you may be able to translate your algorithm in a web project ^^ the elements you could not have learn yet are only: 1) how to do input: prompt(string_to_show); return user input through a dialog box as a string 2) how to output in document/page: document.write(html_string_to_insert); insert and parse html tags don't forgot that default html behaviour treat new lines as spaces and are collapsed... you need to use specific html formatting to achieve line breaks ;) (many ways are possible ^^) try first by yourself, and ask for specific help here if needed (and provide your code attempt, preferably by sharing the link of a code playground project), rather than requesting for full code ;P
3rd Jun 2021, 5:53 AM
visph
visph - avatar
0
well, as 🅰🅹 🅐🅝🅐🅝🅣 give you the almost translation of your python code in javascript, here's mine, getting user input, and outputing in document rather than in console: https://code.sololearn.com/WR7o0132IqDF/?ref=app
3rd Jun 2021, 6:12 AM
visph
visph - avatar
- 2
I have tried this in python but new to javaScript so want to know the syntax for js....
3rd Jun 2021, 4:42 AM
Sneha Bharti