0

What the problem? Where is 'Obey the rules' in to result?

function main() { var day = readLine(); var rules = 'Obey the rules'; if (day<7){ console.log(); } }

22nd May 2021, 6:32 PM
Vladimir Kushner
Vladimir Kushner - avatar
11 odpowiedzi
+ 3
if (day==7) { console.log(rules); } else { console.log(); } log "Obey the rules" if day == 7, else log nothing... but a new line: you could try to remove the else part, as empty line can be considered as wrong output (different from no output at all) ^^
19th Aug 2021, 2:53 PM
visph
visph - avatar
+ 2
Vladimir There is nothing problem. There is only one problem you didn't write logic. Java and JavaScript both are different languages so don't tag Java with JavaScript. Нет ничего страшного. Есть только одна проблема, которую вы не написали логику. Java и JavaScript - это разные языки, поэтому не помечайте Java с помощью JavaScript.
22nd May 2021, 8:09 PM
A͢J
A͢J - avatar
+ 2
if you want to display the string stored in 'rules' when day<7, then you must put 'rules' inside parenthesis of console.log() call: function main() { var day = readLine(); var rules = 'Obey the rules'; if (day<7) { console.log(rules); } } it also could be more safe to convert day to number, even if js should do it for you in this case, by either: var day = Number(readLine()); // explicit var day = +readLine(); // implicit
22nd May 2021, 8:55 PM
visph
visph - avatar
+ 1
with one of the two last line of my first post ^^ Number(string) is the explicit way +string is the implicit way as alternative, you could do it in two lines: var day = readLine(); // day is a string day = Number(day); // day is a number
23rd May 2021, 7:46 PM
visph
visph - avatar
+ 1
if (day<7) { console.log(rules); } log "Obey the rules" if day is less than 7, else log nothing... what is expected by the task? ... and put your full last code attempt ^^ your last one only take input and convert it to number, and the previous one log nothing in all cases (nothing inside the console.log parenthesis -- argument) in addition to have a syntax and logic error (day=7(sunday);)
19th Aug 2021, 1:35 PM
visph
visph - avatar
0
So how to convert day to number in the string of code, I don't understand.
23rd May 2021, 7:41 PM
Vladimir Kushner
Vladimir Kushner - avatar
0
May I'm something doing it not that: function main() { var day = readLine(); var rules = 'Obey the rules'; day=7(sunday); if (day<7){ console.log(); } }
23rd May 2021, 7:56 PM
Vladimir Kushner
Vladimir Kushner - avatar
0
var day = readLine(); day = Number(day); I put these two string but it doesn't to lead a result the task.
19th Aug 2021, 12:15 PM
Vladimir Kushner
Vladimir Kushner - avatar
0
Here is out: function main() { var day = readLine(); //day = Number(day); var rules = 'Obey the rules'; if (day==7){ console.log(rules); } else { console.log(); } }
19th Aug 2021, 2:07 PM
Vladimir Kushner
Vladimir Kushner - avatar
0
Perhaps, I did something wrong... 🤷‍♂️
19th Aug 2021, 2:09 PM
Vladimir Kushner
Vladimir Kushner - avatar
0
Here is out : function main() { var day = readLine(); var rules = 'Obey the rules'; //ваш код if(day == "Sunday"){ console.log(rules); } } // var day = readLine - its string not number
12th Sep 2021, 10:01 AM
Yan Zinchenko
Yan Zinchenko - avatar