8 kyu

Return Negative

142,351 of 373,914Deantwo
Description
Loading description...
Fundamentals
  • Please sign in or sign up to leave a comment.
  • DuduSMistrz Avatar

    Every time I do simple kata a learn new think from std.math. Thanks ;)

  • gigrdo Avatar

    This comment has been hidden.

  • oleks16 Avatar

    What???????? My dad are a programmer

  • dhimanharsh Avatar

    why they return the answer wrong?????

  • ThominatorMk7 Avatar

    This comment has been hidden.

  • @justDev Avatar

    Hello how to do this is question

  • missed_a_semicolon Avatar

    This comment has been hidden.

  • vilstrong Avatar

    This comment has been hidden.

  • LuucasNunes Avatar

    This comment has been hidden.

  • mohyswe Avatar

    There's a minor improvement to be made to your test suite. Currently, it only evaluates the function with a single input value (42). It's advisable to include multiple test cases covering a broader spectrum of scenarios. This ensures thorough testing and verifies that the function behaves correctly across various input types, including positive, negative, and zero values.

  • Brian Mweu Avatar

    An easy one! passed

  • muhammadqasim3 Avatar

    This comment has been hidden.

  • swatsniper6 Avatar

    This comment has been hidden.

  • kavakoza Avatar

    This comment has been hidden.

  • ch-tactica Avatar

    Site is busted, wouldn't accept my solution but the tests all passed :(

  • okkadu Avatar

    works for me - make sure your solution return, but not print().

  • gemy141 Avatar

    This comment has been hidden.

  • Thornasco Avatar

    Hello, I don't understand what to do...

  • AlexGoIT23 Avatar

    My code works completely on any tests both here and in VSC, but the system writes an error "expected 9 to equal -9"!

  • Karumu05 Avatar

    I keep getting the error "undefined should equal -9" is this something i am doing wrong ? When I click test it says everything is complete but when I click attempt it doesnt work

  • Khangmeme421 Avatar

    main.cpp:9:5: error: conflicting types for 'main' int main(int, const char *[]) { ^ What's wrong?

  • akar-0 Avatar

    NASM fork with more informative tests logs.

  • Raduq91 Avatar

    NASM

    Time: 646ms Passed: 4Failed: 3Exit Code: 1
    Test Results:
    negative_one_test
    should_return_negative_value
    The expression (make_negative(-1)) == (-1) is false.
    Completed in 0.9982ms
    Completed in 0.9982ms
    negative_test
    should_return_negative_value
    The expression (make_negative(-9)) == (-9) is false.
    Completed in 0.6710ms
    Completed in 0.6710ms
    one_test
    should_return_negative_value
    Completed in 0.3418ms
    positive_test
    should_return_negative_value
    Completed in 0.5889ms
    random_negative_test
    should_return_negative_values
    The expression (actual) == (expected) is false.
    Completed in 1.0609ms
    Completed in 1.0609ms
    random_positive_test
    should_return_negative_values
    Completed in 0.8125ms
    zero_test
    should_return_zero_value
    Completed in 0.6491ms
    
  • 0FSener Avatar

    This comment has been hidden.

  • A_S_86 Avatar

    This comment has been hidden.

  • hobovsky Avatar
  • hobovsky Avatar
  • KayleighWasTaken Avatar

    CoffeeScript fork

    Adds random tests.

  • wbarajas Avatar

    This comment has been hidden.

  • fuyuyu Avatar

    im a literal genius

  • Anilberke Avatar

    This comment has been hidden.

  • P0intworthy Avatar

    So my kata works on my local machine, in a Jupyter notebook. But here, I get errors because I didn't do it the same as the solution and I'm not importing something that the solution has. Also my first kata wouldn't work because I asked for input, which apparently isn't available. So how do you get around this without just copying their solution?

  • KEVINPRACTICEYUAN Avatar

    El kata muy bien.

    Hay no problemas en mi código!

    :)

  • EvelinAlvarado Avatar

    This comment has been hidden.

  • menotso Avatar

    Language Translation to Portuguese-Brazil:

    Descrição

    Neste simples projeto, dado um número, você deve fazẽ-lo ficar negativo. Mas talvez este número já seja negativo?

    Exemplos

    make_negative(1); # retorna -1 make_negative(-5); # retorna -5 make_negative(0); # retorna 0

    Notas

    O número pode já ser negativo, tal qual nenhuma mudança é necessária. Zero (0) não é verificado para nenhum sinal específico. Zeros negativos não possuem sentido matemático.

  • craigM222 Avatar

    I am confused as to how to start many of these. I haven't done enough of them to get the pattern. I am a little autistic so sometimes the words don't make sense. I understand what to check for but what am I checking? DO I need to specify an input toget the numbers? IF I don't understand that I cannot deal with the rest of the logic.

  • FRANZ0091 Avatar

    It took me a little while to realize that I was checking if the number was a negative instead of positive lol.

  • FinzyPHINZY Avatar

    This comment has been hidden.

  • Hazem ibrahim Avatar

    This comment has been hidden.

  • TankEngine Avatar

    This comment has been hidden.

  • imonisi Avatar

    This comment has been hidden.

  • monkey_on_a_keyboard_1 Avatar

    difficult kata, but eventually i got the hang of it after a few hours

  • sairilseb Avatar

    This comment has been hidden.

  • EEv9ENN Avatar

    This comment has been hidden.

  • A_Kam Avatar

    my test passed the first time and the submission was wrong so i added the if condition

  • Sodiqjon Avatar

    bu biroz qiyinroq

  • SaloJuan Avatar

    This comment has been hidden.

  • dex_lec Avatar

    This comment has been hidden.

  • Aba06 Avatar

    This comment has been hidden.

  • NadavIvry19 Avatar

    This comment has been hidden.

  • AmberYang Avatar

    This comment has been hidden.

  • alexa_m_r Avatar

    This comment has been hidden.

  • dyeov_gein Avatar

    This comment has been hidden.

  • programmerXS Avatar

    The test is passed, but when I hit attemp now the test doesn't work. In both test and attemp have the same sample.

  • TomasVainstub Avatar

    I does this exercise in visual and after that pass here but doesnt work, why?

  • nereno96 Avatar

    When I solved this kata in python, one of the tests was incorrect. It expected -9 as a result for the input -9, when the result should have been 9 instead

  • user7648366 Avatar

    when I tried to run the code outside codewarriors.com it worked, but it won't in codewarriors. What should I do?

  • ProgrammingHeadache Avatar

    This comment has been hidden.

  • kryoo Avatar

    Warm up

  • leosouza-v11 Avatar

    That was easy!

  • roses-are-dead666 Avatar

    This comment has been hidden.

  • NoxaGen Avatar

    This comment has been hidden.

  • Kasmasov Avatar

    This comment has been hidden.

  • daanrox Avatar

    Lets Fun!!

  • Varunanda Avatar

    This comment has been hidden.

  • Ariasware Avatar

    This comment has been hidden.

  • akar-0 Avatar
  • Kacarott Avatar
  • florovme Avatar

    Does not work well for me,alse chked in idle works fine

  • Hollas Avatar

    This comment has been hidden.

  • jmroigcourtis Avatar

    This comment has been hidden.

  • Grregory92 Avatar

    This comment has been hidden.

  • kir8313 Avatar

    This comment has been hidden.

  • juliacrbn Avatar

    the test cases were wrong

  • mcozkan Avatar

    This comment has been hidden.

  • Beveled Avatar

    This comment has been hidden.

  • DeclanR Avatar

    "expected 9 to equal -9" but my function returns -9?? not really sure what I'm doing wrong here

    Nevermind my fault did not read the description properly

  • piepelniCa Avatar

    This comment has been hidden.

  • Falcon_007 Avatar

    This comment has been hidden.

  • Toples Avatar

    This comment has been hidden.

  • user4197517 Avatar

    This comment has been hidden.

  • akar-0 Avatar

    COBOL translation updated to new test suite.

  • ShivaGrace Avatar

    Hi! im new at codewars, figuring out how to use it and learning to program. This is the first excercise im doing here and i don't understand why if i put "test" and everything turns to be ok, when i select "atempt" it says i failed. I may have failed as im new at this, but i would like to understand whats the difference between one and the other.

  • sabrinaachille Avatar

    i see that for some of the codes using abs, some use include cmath and some do not, so when do you need to use cmath?

  • akar-0 Avatar

    COBOL translation available for review!

  • AnOccwordBonar Avatar

    make usre you return num;}

  • ABS-12 Avatar
  • h-p-wilson Avatar

    You cannot use x for some reason, I had to create a new int y and return that, can anyone explain why using x is an issue?

  • Oron-2 Avatar

    This comment has been hidden.

  • Deantwo Avatar

    @hobovsky, why are you trying to change the code examples in the description? You keep changing it to:

    Input:  1  =>   Output: -1
    Input: -5  =>   Output: -5
    Input:  0  =>   Output:  0
    

    That is not better than the current, and I see no reason to change it to that.

  • zhandosweb Avatar

    This comment has been hidden.

  • Agustin93 Avatar

    This comment has been hidden.

  • asqararslonov2008 Avatar

    This comment has been hidden.

  • Jimpix Avatar

    Very fun exercise!

  • CyannRogue Avatar

    This comment has been hidden.

  • bbaymistery Avatar

    This comment has been hidden.

  • ejini战神 Avatar

    My first attempt on R translation. Please review and approve ~~

  • Anil07 Avatar

    This comment has been hidden.

  • hydromoll Avatar

    This comment has been hidden.

  • ngocthuan94 Avatar

    This comment has been hidden.

  • WombleWoo7547 Avatar

    This comment has been hidden.

  • FArekkusu Avatar

    C version generates warnings.

  • dolamroth Avatar

    C-version should have random tests. Docs: https://docs.codewars.com/authoring/guidelines/submission-tests

  • FArekkusu Avatar

    C version generates warnings.

  • ejini战神 Avatar

    Julia should use camel_case / camelcase

  • ejini战神 Avatar

    Converted language-specific blocks into language-agnostic description

  • Codynw42 Avatar

    This comment has been hidden.

  • ejini战神 Avatar
  • cool.wirya Avatar

    This comment has been hidden.

  • kps_barroso Avatar

    This comment has been hidden.

  • Engineer gaming Avatar

    Why It does'nt accept scanf and printf?

  • ejini战神 Avatar

    Forked python translation with new test framework used and 3.8 enabled

  • Asith Avatar

    My solution is very basic and easy for py3 I hope it's helpful.

  • johanperjulius1 Avatar

    This comment has been hidden.

  • euronymoos Avatar

    The starting function name is makeNumberNegative(), however the test requires makeNumber() ...

  • Joel.K Avatar

    This comment has been hidden.

  • bhavya_1211 Avatar

    This comment has been hidden.

  • Howemanning Avatar

    This comment has been hidden.

  • Stecom2203 Avatar

    I'm really confused ! Anytime I test the code it runs but when I attempt, all of them are errors, even the one of the Test. Can anyone help me please?

  • ianvazperez Avatar

    This comment has been hidden.

  • Daswf852 Avatar

    this should be a 1 kyu kata :^)

  • Teisenhower Avatar

    Hello!

    Maybe a good test case to add would be a value that is NaN. Requiring solutions to ignore anything that is NaN and simply return that value passed.

    makeNegative("Hello, I'm not a number..") // simply returns 'Hello, I'm not a number..'
    
  • will5023 Avatar

    This comment has been hidden.

  • KarenL Avatar

    my first Kata and I´m proud that I can solve it.

  • mitron6 Avatar
  • pinteck Avatar

    Great exercise for a simple "If Statement" practice. Thanks!

  • yozanshin Avatar

    I'm afraid that tests are broken for Java and Go, assertions are wrong as they expect incorrect results in some cases...

  • user8436785 Avatar
  • user8436785 Avatar

    A PHP translation has been waiting for a while, anyone want to approve it?

  • CodeKrakken Avatar

    This comment has been hidden.

  • TuCrG123 Avatar

    how do i do this? I couldn't do it by myself and so I looked on google on how to turn a postive number into a negative number but i still don't understand where to put the code or if i have to modify the code to suit my program.

  • GHOST! Avatar

    This comment has been hidden.

  • d08 Avatar

    This comment has been hidden.

  • tooney Avatar

    This comment has been hidden.

  • Paradox_Night Avatar

    This comment has been hidden.

  • xavierguihot Avatar

    Scala translation available for review.

  • IonutArhire Avatar

    This comment has been hidden.

  • JeshK92 Avatar

    Good easy to understand Kata.

  • Prometheus1621 Avatar

    This comment has been hidden.

  • hibbarra Avatar

    I cannot locate where to put my code. What is up with this kata.

  • Souzooka Avatar

    Hi, I made a NASM translation for this Kata.

  • Coolcoder9 Avatar

    This comment has been hidden.

  • cgrzegorz Avatar

    This comment has been hidden.

  • ASDFGerte Avatar

    Javascript (and potentially other languages): Faulty or missing test cases for potential -0, although the case is explicitly mentioned in the description (the kata is too old to change test cases, but afaik the description can still be modified).

    This has been mentioned here before, but imho is simply a mistake and should be an issue, not some half hearted comment that can be ignored.

  • petrarch1603 Avatar

    maybe this it too easy....

  • Chrono79 Avatar

    Needs edge case like -1 in all languages (see lobo_tuerto's post below). Also sample tests are missing in Ruby. I raise an issue so I (or any other power-user) can add it in a week.

  • LondonJim Avatar

    Ruby version doesn't have any test conditions

  • FrozenPigs Avatar

    This comment has been hidden.

  • lobo_tuerto Avatar

    This comment has been hidden.

  • Ndavis111 Avatar

    It says that variable x might not be assigned. Please help.

  • stazman Avatar

    This comment has been hidden.

  • inzkhan Avatar

    Thanks for sharing this kata .

  • Hectolimar Avatar

    testcase 2 for java reads: assertEquals(-9, Kata.makeNegative(-9));

  • ErSaurabhSG Avatar

    code pane is non editable I am not able to submit my solution

  • POMIDORR Avatar

    What is "Assert::That"?

  • DeathForPuppets Avatar

    For JavaScript expects "-0" as a result. Which you described as n/a in the description.

  • joydeeproy87 Avatar

    This comment has been hidden.

  • taadis Avatar

    This comment has been hidden.

  • bestwebua Avatar

    Thanks, so nice kata!

  • owenmech Avatar

    The submit Final button is missing for me.

  • globalkeith Avatar

    The Elixir test is wrong, perhaps you could update it to reflect the description?

  • jechol Avatar

    simple check (2.3ms)

    1. test simple check (TestNegator) fixture:5 Assertion with == failed code: make_negative(-42) == 42 lhs: -42 rhs: 42 stacktrace: fixture:6

    Test case make_negative(-42) == 42 is incorrect. broken.

  • ultimastorm Avatar

    For Elixir the tests needs to be updated

    assert make_negative(-42) == 42, is not according to the description, expected result should be -42.

    And in the hidden tests:

    fixture:20: warning: random:uniform/1: the 'random' module is deprecated; use the 'rand' module instead
    fixture:27: warning: random:uniform/1: the 'random' module is deprecated; use the 'rand' module instead
    
  • SindhuMadhuri Avatar

    Is the second test case right? Shouldn't it be 9 instead of -9 somewhere?

  • user9739102 Avatar

    This comment has been hidden.

  • nickie Avatar

    In Haskell, this kata is harder than in other languages, if one is not allowed to change the polymorphic signature that just mentions Num a and not Eq a or Ord a. The description should mention whether adding more class constraints is allowed or not. If not, there should be test cases checking for this, and the kata should probably be worth more points.

  • squarebe Avatar

    on ruby it gives an unknown error msg. have no idea if my code works or not just an error msg.

  • AngusJGoldsmith Avatar

    Submitted Java translation.

  • asc2683 Avatar

    This comment has been hidden.

  • marinoemarques Avatar

    Ok, solved it the hard way, but I'm learning.

  • tikitariki Avatar

    One solution returned the number as a string. I think the data type should remain a number since that is what you would expect from a function like this. A string shouldn't pass because it isn't even really a number anymore.

  • ianwhitedeveloper Avatar

    This comment has been hidden.

  • kristaps Avatar

    As a beginner, I am just wondering, is my code just too big or takes too many lines ? Is it just experience that "shrinks" the code in ones head ?

  • Deantwo Avatar

    This comment has been hidden.