- 4
How to print pattern using # and * alternatively using JavaScript?
#*#*#*#*#* *#*#*#*#*# #*#*#*#*#* *#*#*#*#*#
7 Antworten
0
Sneha Bharti
Show your attempts.
https://www.sololearn.com/post/1115272/?ref=app
+ 1
Sneha Bharti
How did you try in python?
+ 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
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")
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
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
- 2
I have tried this in python but new to javaScript so want to know the syntax for js....