+ 1

Valid Binary String challenge

I’m trying the binary challenge for beginners. It doesn’t work that well though.. could you please tell what is wrong in my code ? Thank you https://code.sololearn.com/WoRmMVeQP7Zn/?ref=app

18th Jan 2019, 8:59 AM
Andrea Vinci
Andrea Vinci - avatar
4 odpowiedzi
+ 3
I don't know JavaScript buddy 😄, but I've submitted my assignment. You can take benefit from it. Hope it helpful. 😄 https://code.sololearn.com/cSdv761LCgm1/?ref=app
19th Jan 2019, 1:25 AM
Ayush Sinha
Ayush Sinha - avatar
+ 2
- prompt already returns a string, so no need to use toString() - your test is always true, anything is always not "0" or not "1", use && instead of || - you should print outside of the loop once you have determined if the whole input is binary or not, and not once per loop Here is my shot at it: https://code.sololearn.com/WBtEXv8jAZEs/#js
18th Jan 2019, 10:23 AM
Zen
Zen - avatar
+ 1
First thing : Your test is always thrue with binary number because a binary digit is always 0 || 1. A binary digit is either 1 thus !=0 or 0 thus !=1. You must test &&. (If I have understood your intention...) Next, you should either print Your result out of the loop for no repetition or better out of the function. My solution : https://code.sololearn.com/WX3SUtwaS586/?ref=app
18th Jan 2019, 10:03 AM
Étienne Durup
Étienne Durup - avatar
+ 1
https://code.sololearn.com/cgNsaOhLAfQh/?ref=app
19th Nov 2021, 9:48 AM
Neeraj Kumar
Neeraj Kumar - avatar