#[Swift] Error found on Exercism
88 messages · Page 1 of 1 (latest)
What makes one order more correct than the other?
ie why is the order in the test wrong and your code right vs the tests being right?
I just test the exercise and there is nothing wrong with it if you follow the instruction correctly.
Define the function totalTimeInMinutes(layers:elapsedMinutes:)
@formal cobalt did you get it sorted?
No not yet sorry I had to step away to eat, lemme check what everyone else posted here in a sec
Can you help?
This is the code it works perfectly in the swift debugger, but fails when running the swift test command
please post code in codeblock and not screenshot
using 3 backticks ` to wrap it at the beginning and end
def hello():
print("Hello, World")
also when you said your code works perfectly, what does this mean? Did you run it in your own environment against nothing? Did you run it against the test suites? On the web editor? Or using cli tools?
let expectedMinutesInOven = 40
// TODO: define the 'remainingMinutesInOven' function
func remainingMinutesInOven(elapsedMinutes eM: Int) -> Int {
let timeE = expectedMinutesInOven - eM
return timeE
}
//print(remainingMinutesInOven(elapsedMinutes: 3))
// TODO: define the 'preparationTimeInMinutes' function
func preparationTimeInMinutes(layers l:Int) -> Int {
let amountL = 2 * l
return amountL
}
//print(preparationTimeInMinutes(layers: 2))
// TODO: define the 'totalTimeInMinutes' function
func totalTimeInMinutes(elapsedMinutes eM:Int, layers l:Int) -> Int {
let timeT = remainingMinutesInOven(elapsedMinutes: eM) + preparationTimeInMinutes(layers: l)
return timeT
}
I ran it using the .run code runner swift vscode extension
what is the original interface/ stub of the 3rd function totalTimeInMinutes
you can revert your exercise to the beginning with the 3 dots on upper right of the website
and revert it back to the beginning
what is your question? there was no code in the file originally all of it was edited in by me
i see. so swift did thing a bit different. usually other tracks have things predefined
well, what is the instruction then
I left all of the comments in the code block above
the "TODO"
were the original
Also I would like to state that once again it works when you reverse those lines in the checker file. for some reason
No, I wan you to give me the instruction on the webpage.
The one from the right panel saying
Task 4 Calculate the total working time in minutes
blah blah blah
Oh one sec
This is the link to it
kk
- Calculate the total working time in minutes
Define the function totalTimeInMinutes(layers:elapsedMinutes:) that takes two arguments: the layers parameter is the number of layers you added to the lasagna, and the elapsedMinutes parameter is the number of minutes the lasagna has been in the oven. The function should return how many minutes in total you've worked on cooking the lasagna, which is the sum of the preparation time in minutes, and the time in minutes the lasagna has spent in the oven at the moment.
totalTimeInMinutes(layers: 3, elapsedMinutes: 20)
// Returns 26
Define the function totalTimeInMinutes(layers:elapsedMinutes:)
and this is your code
func totalTimeInMinutes(elapsedMinutes eM:Int, layers l:Int)
did you see what's going on now?
yeah thats how you define a function
the way they wrote it in the website is incorrect
you cant define a function without the keyword func
and you cant pass an argument to a function without an argument label
im not talking about the name or keyword. im talking about the order of the paramaters
oml that is so stupid but ok, just saying it would make more sense if the checker script accounted for reversability, because if you go off of the order that things are defined it should be elsapsedMinutes first with Layers second
im not the one who design or create it. if you have suggestion to improve it, feel free to make a thread on forum and talk to the maintainer
I might just make a fork and propse a commit on the github for it
Thanks for the help though
keep in mind this is a very first exercise for beginners
that helps to understand what's a basic function
correct which is why it should be reversable to curb cases of confusion
what you already knew might not be what they do know, esp when it come to language when function doesnt have named param
Yeah sure im just saying it would be a good edition because its better to acount for edge cases then to leave aspiring coders confused as to why their code isnt running
But thanks for the help
and for pr etiquette, consider open a forum post and talk about it first to the maintainer before making any PR
or else it would just be ignored
true thanks
@scenic island Hey I tested the fix that you said to do and it throws an error because the layers has to be passed last and the elapsedMinutes has to be passed first as in swift functions take argument labels in order of declaration
what is your code now and what is the error? please dont use screenshot
i copied your code before you deleted and im pretty sure the problem is in the logic
Ok I am very sorry it is not an issue with the code
Yes I found my error
Turns out that wasnt the issue
Let me show you
This is the first instruction of the problem:
- Define the expected oven time in minutes
Define the expectedMinutesInOven constant, that stores how many minutes the lasagna should be in the oven. According to the cooking book, the expected oven time in minutes is 40:
See how it says that the oven time should be set to 40?
no, it is not the oven time. it is the expected constant
no it is the oven time
// TODO: define the 'expectedMinutesInOven' constant
Oh?
i mean it even said so in the paragraph you posted..
why are you arguing over literal facts
Yeah thats what I am refering to
The expected oven time
it is the issue
just let me explain first please
In the problem it says to define it as a constant as 40
If we look at the math, the math will subtracted the remaining time from the expected time
math for what?
Hold I am very sorry let me lay this out in a draft and then send it, because this is a serious error I can explain it better if you give me like 5 minutes sorry
let me just offer this one tiny advice
make sure you understand what elapsedMinutes mean
and it would make sense for the whole thing
Yeah I will make sure to double check the way I state it in the message I will send
But yes I can 100% garentee this is an error so just give me on second
sure, and im 100% sure that it isn't, but go ahead
Hey sorry for being a pain and a waste of your time, I figured out my error
no problem. figure out the error and fix it is a good skill to have
Yeah thanks for helping me through it
Rubber duck debugging. Sometimes the most helpful thing you can do is to encourage someone to explain the problem.
Well, since this is all resolved. I will ask to close the open issue on the track as well.