0
What is wrong with this code the snake in the well .I need help pls
function main() { var depth = parseInt(readLine(), 10); //your code goes var A =0; var Day=0; while(A<= depth){ A+=7-2; Day+=1; } if(A>=depth){ console.log(Day) } }
6 Answers
+ 9
1. You should start day at 1
2. Loop until out of the well
3. In the loop first add how much you climb up in a day.
4. Then check if you are out of the well. If yes break out of the loop.
5. If not drop the distance you drop at night and add 1 to the day.
6. After the loop output the number of days it took you to get out of the well.
+ 4
@ChaoticDawg I completly agree with what you just said. But with one hesitation! When you're spoon feeding a bit of logic, do it within the framework of student's logic not your own logic. Because even if we're talking about a simplest logic, his logic will completly differ from yours right from the beginning. Logic should be provided in portions, so that it does not leave behind all the pitfalls for the student. After all, it is they who are the best teacher. So we need to help him in accordance with his logiŃ trying to direct it in a right way, in the places where the logic went off the right direction.
+ 3
First of all, your loop will iterate 3 times:
1. while (0 <= 10) true, iterates
2. while (5 <= 10) true, iterates
3. while (10 <= 10) true, iterates
So after 3 iterations your 'Day' variable will have value '3'. The problem here is that during the second iteration in your while loop your variable 'A' already reaches desired value which is '10' in variable 'depth'. So at this point you already need to console log your 'Day' variable.
+ 3
I believe that people should not answer in this way when the answer is almost a ready-made solution. Such answers limit the student as much as possible from the learning process by overcoming difficulties. In his head, he looked for solutions and wrote some code. And now he will just jump from what was in his head to an almost ready answer. He will jump from the process that really taught him to the process where he will simply write the code from the ready answer and forget it all.
+ 2
Artur
Not a single line of code was given. Just the thought process. I would say it's much better than even giving pseudocode or full code answers. The OP still needs to be able to write the code themselves. You'd be surprised be how many will still have issues even after spoon feeding a bit of logic to them. I've also found in my several years of helping people learn to code that it doesn't always help someone who is new to have them concentrate on both writing the code properly and solve the logic of the problem at the same time. This level of skill will come with time, and showing a bit of minor typical coding logic to a noob can help them greatly in the future when they are doing it themselves, as they can see how to work things out logically and write down the steps before ever coding a single line. (Think coding interview). Just my opinion, you can feel free to agree or disagree and neither of us would be correct. đ
+ 1
ChaoticDawg Ah man, this is not interesting... You just gave him almost full answer.