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(); } }
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) ^^
+ 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.
+ 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
+ 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
+ 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);)
0
So how to convert day to number in the string of code, I don't understand.
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();
}
}
0
var day = readLine();
day = Number(day);
I put these two string but it doesn't to lead a result the task.
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();
}
}
0
Perhaps, I did something wrong... 🤷♂️
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