#[Swift] Error found on Exercism

88 messages · Page 1 of 1 (latest)

mellow marlin
#

It sounds like the issue is that your code and the test code expect the args to be in different orders.

#

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?

scenic island
#

I just test the exercise and there is nothing wrong with it if you follow the instruction correctly.
Define the function totalTimeInMinutes(layers:elapsedMinutes:)

mellow marlin
#

@formal cobalt did you get it sorted?

formal cobalt
formal cobalt
#

This is the code it works perfectly in the swift debugger, but fails when running the swift test command

scenic island
#

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?

formal cobalt
#
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
}
formal cobalt
scenic island
#

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

formal cobalt
#

what is your question? there was no code in the file originally all of it was edited in by me

scenic island
#

i see. so swift did thing a bit different. usually other tracks have things predefined
well, what is the instruction then

formal cobalt
#

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

scenic island
#

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
formal cobalt
#

Oh one sec

scenic island
#

I want the blah blah blah part

#

The first sentence should be enough

formal cobalt
#

This is the link to it

scenic island
#

please copy and paste it here

#

the instruction for task 4

formal cobalt
#

kk

#
  1. 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

scenic island
#
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?

formal cobalt
#

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

scenic island
#

im not talking about the name or keyword. im talking about the order of the paramaters

formal cobalt
#

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

scenic island
#

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

formal cobalt
#

I might just make a fork and propse a commit on the github for it

#

Thanks for the help though

scenic island
#

keep in mind this is a very first exercise for beginners

#

that helps to understand what's a basic function

formal cobalt
scenic island
#

what you already knew might not be what they do know, esp when it come to language when function doesnt have named param

formal cobalt
#

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

scenic island
#

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

formal cobalt
#

true thanks

formal cobalt
#

@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

scenic island
#

what is your code now and what is the error? please dont use screenshot

formal cobalt
#

ok lemme send it one sec

#

wait a minute one sec

scenic island
#

i copied your code before you deleted and im pretty sure the problem is in the logic

formal cobalt
#

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:

#
  1. 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?

scenic island
#

no, it is not the oven time. it is the expected constant

formal cobalt
#

no it is the oven time

scenic island
#

// TODO: define the 'expectedMinutesInOven' constant

formal cobalt
#

Oh?

scenic island
#

i mean it even said so in the paragraph you posted..

#

why are you arguing over literal facts

formal cobalt
#

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

scenic island
#

math for what?

formal cobalt
#

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

scenic island
#

let me just offer this one tiny advice

#

make sure you understand what elapsedMinutes mean

#

and it would make sense for the whole thing

formal cobalt
#

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

scenic island
#

sure, and im 100% sure that it isn't, but go ahead

formal cobalt
scenic island
#

no problem. figure out the error and fix it is a good skill to have

formal cobalt
mellow marlin
scenic island
#

Well, since this is all resolved. I will ask to close the open issue on the track as well.