- 3
Help
function main() { var depth = parseInt(readLine(), 10); //your code goes here var depth = } https://code.sololearn.com/czR3FUuWrPUj/?ref=app
14 Answers
+ 3
How about your attempt?
+ 1
Emmanuel Pena And stop posting new comments with copies of the code. This makes it harder and harder to find information among too many comments.
+ 1
OK. Some questions:
1. What is the purpose of variable "depth"? The code gets it from the user, but never uses it again.
2. Why do you initialize variable "day" with 7?
3. What is the logic behind the series of "if"s?
And some recommendations:
1. Review the "if" statement syntax.
2. Take a good read on loops. No hurry - I mean a good read indeed.
0
The snail climbs up 7 feet each day and slips back 2 feet each night.
How many days will it take the snail to get out of a well with the given depth?
Sample Input:
31
Sample Output:
6
Explanation: Let's break down the distance the snail covers each day:
Day 1: 7-2=5
Day 2: 5+7-2=10
Day 3: 10+7-2=15
Day 4: 15+7-2=20
Day 5: 20+7-2=25
Day 6: 25+7=32
So, on Day 6 the snail will reach 32 feet and get out of the well at day, without slipping back that night.
0
function main() {
var depth = parseInt(readLine(), 10);
//your code goes here
var day =7
if(day 1, 7-2=5){
break; {
if (day 2, 5+7-2){
break;{
if(day 3 12+7-2){
break;
if (day 4 19+7-2){
break;{
if(day 5 26+7-2){
break;{
console.log (day)
}
0
This doesn't seem valid syntax. Also, do you notice how the steps repeat themselves? Shouldn't them be in a loop instead?
Before anything else, pls add two important fixes to the question itself:
1. Replace all tags with a single one with the language name
2. Put your started code in Code Playground and add a link to it in the question description - use "+" button
With these simple actions, we'll fix the code step by step.
0
I dont know how share a link
0
??
0
function main() {
var depth = parseInt(readLine(), 10);
//your code goes here
var day =7
if(day 1, 7-2=5){
break; {
if (day 2, 5+7-2=10){
break;{
if(day 3 12+7-2=17){
break;
if (day 4 19+7-2=24){
break;{
if(day 5 26+7=33){
break;{
console.log (day)
}
0
Anybody could help ?
0
Emmanuel Pena Go to code section, paste your code and save as public. Then, come back to the question, tap the 3 dots, then Edit. Go to the question description, tap "+", select "Code", then choose the one you saved.
0
Sorry wont happen again , but i did what you said take a look
0
Thank u so much !!
0
Shree Kumar Pls avoid giving finished code as answer, because it makes the OP skip the most important part of learning process. Prefer giving hints for the OP to find the solution.