+ 3
I need help with my second java script code coach. Please help me!!!
15 ответов
+ 6
for(let x=0 ; ; x -= 2) {
i += 1;
x += 7;
if( x >= depth)
break;
}
Goes like this, better to use while loop..
You're welcome...
+ 6
function main() {
var depth = parseInt(readLine(), 10);
//your code goes here
var i=0
for(x=0; x<="depth"; x+=5)
{
i+=1
console.log(i)
}
}
Here it is.
+ 5
function main() {
var depth = parseInt(readLine(), 10);
//your code goes here
var i=0
for(x=0; x<depth; x+=7)
{
if (x<depth){
x-=2
i+=1
}
else {
break
}
}
console.log(i)
}
Hi, I've tried changing but there is still a little bug in it.
+ 4
That's the problem Techna💖💕😎 , can you copy your code so far into the code playground and share it here?
+ 3
The snail climbs up 7 feet each day and slips back 2 feet each night.
Write a program to calculate how many days will it take the snail to get out of a well with the given depth.
+ 3
Thanks so much.
+ 3
It worked thank you Jayakrishna
+ 2
Where is code? What is the problem?
+ 2
Techna💖💕😎
It is javascript code. Not java code.
Errors:
x is undeclared.
anything put in quotes "here" , becomes a string. So "depth" Is a string , not variable so x <= "depth" Is invalid. Use x < depth;
No need to output anything inside loop as task asked to output only number of days.
Reform these steps :
Declare a variable for day before loop.
Inside loop start climbing
* up 7 so add 7.
increment day,
if you reach depth stop it;
Otherwise down 2 so subtract 2
Repeat this until finish.
* Display day value.
Understand it and try again....
+ 2
Techna💖💕😎 Your code does like this :
x = 0
x < depth :: true so x -= 2 => x = -2 without starting done down. (Next adds 7). Which leads wrong result.
so
First add 7. Then decrement 2 if not reached depth.
I += 1 should be in each iteration so irrespective of any condition. Add it outside if block. Better as first line.
+ 2
Hi happy program's day
+ 1
Very beautiful what a beautiful specialty
+ 1
items = ["Rock ✊", "Paper 📃", "Scissor ✂️"]
#AI
0
Hello
0
سلام