Skip to content

Instantly share code, notes, and snippets.

@TheMuellenator
Last active April 16, 2024 04:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save TheMuellenator/9fe2f689a3e1d9aec2fd631bd98ec606 to your computer and use it in GitHub Desktop.
Save TheMuellenator/9fe2f689a3e1d9aec2fd631bd98ec606 to your computer and use it in GitHub Desktop.
iOS repl.it - Functions 3 Challenge Solution
func isOdd(n: Int) -> Bool {
if n % 2 != 0 {
return true
} else {
return false
}
// Alternatively:
// return n % 2 != 0
}
let testNumber = Int(readLine()!)!
let numberIsOdd = isOdd(n: testNumber)
print(numberIsOdd)
@benho1512
Copy link

testNumber = 5
return true

@MohamedGamalElSherbiny
Copy link

//Create your function here:
func isOdd(n: Int) -> Bool {
if n % 2 == 1 {
return true
}
else {
return false
}
}

//Do not change the code below.
let testNumber = Int(readLine()!)!
let numberIsOdd = isOdd(n: testNumber)
print(numberIsOdd)

@banchito
Copy link

func isOdd(n: Int) -> Bool{
if n % 2 == 0{
return false
}else{
return true
}
}

% operator is my fave!

@gerisztein
Copy link

func isOdd(n: Int) -> Bool {
  return n % 2 != 0
}

@jihredoy
Copy link

func isOdd(n: Int) -> Bool { return n % 2 != 0 }

@patterson-dtaylor
Copy link

Mine is the same as 👆.

@MohamedGamalElSherbiny
Copy link

I think she wanted us in this challenge to use if else. Thats why our answer was like that, but your answers are valid too. But won't be answering the challenge using if else.

@Zylak
Copy link

Zylak commented Apr 29, 2020

func isOdd(n: Int) -> Bool {

let n = n

if n % 2 == 0 {
return false
} else {
return true
}
}

@04wakeup
Copy link

04wakeup commented May 9, 2020

same here

@vivekkumar198
Copy link

func isOdd(n: Int) ->Bool{
if (n % 2 == 0){
return false
}
else {
return true
}
}

//Do not change the code below.
let testNumber = Int(readLine()!)!
let numberIsOdd = isOdd(n: testNumber)
print(numberIsOdd)

@mw00
Copy link

mw00 commented Jun 4, 2020

func isOdd(n: Int) -> Bool {
if n % 2 != 0 {
return true
} else {
return false
}
}

I did exactly this code but my console was returning error. After 10min trying to understand I just realised that my B on Bool wasn't in capital letter. Damn

@gyos23
Copy link

gyos23 commented Jun 5, 2020

Solution:

func isOdd(n: Int) -> Bool {
if n%2 == 1 {
return true
} else {
return false
}
}

@kpacholak
Copy link

ha! another one

func isOdd(n: Int) -> Bool {
  if n % 2 == 0 {
    return false
  } else {
    return true
  }
}

@hackerman518
Copy link

func isOdd(n: Int) -> Bool {
// Number not divisible by 2
if n % 2 != 0 {
return true
} else {
return false
}
}

@Dimanikin
Copy link

func isOdd(n: Int) -> Bool {
if n % 2 != 0 {
return true
} else {
return false
}
}

isOdd(n: 5)

@TusharWoody
Copy link

BelowSolutionWorksWellButStillDontKnowWhatThisSymbol%Indicates
func isOdd(n: Int) -> Bool {

if n % 2 != 0 {
    return true
} else {
    return false
}

}
isOdd(n: 5)
isOdd(n: 7)

@ICiovica
Copy link

func isOdd(n: Int) -> Bool{
if n % 2 == 0{
return false
}else{
return true
}
}

% operator is my fave!

And how do you call this function

BelowSolutionWorksWellButStillDontKnowWhatThisSymbol%Indicates
func isOdd(n: Int) -> Bool {

if n % 2 != 0 {
    return true
} else {
    return false
}

}
isOdd(n: 5)
isOdd(n: 7)

How do you call this function ?
When I type "isOdd(n: 5)" I got "Expressions are not allowed at top level"

@chinnibindhu
Copy link

func isOdd(n:Int) ->Bool {
if n%2 == 0{
return true
}
else{
return false
}
}
let testno = Int(readLine()!)!
var res = isOdd(n:testno)
print(res)

@bnbrwd
Copy link

bnbrwd commented Nov 13, 2021

This is my solution

func isOdd(n: Int) -> Bool {

    if n % 2 != 0 {
        return true
    } else {
        return false
    }
}

@Magdalenaspace
Copy link

func isOdd(n: Int) -> Bool { return n % 5 != 0 }

let numberIsOdd = isOdd(n: 53)
print(numberIsOdd)

@b-abdenoure
Copy link

i used this
f```
unc isOdd (n: Int) -> Bool{
if n % 2 == 0 {
return false
}else{
return true
}
}

there is many way to make it work

@EdoardoTunzi
Copy link

THIS ONE WORKED FINE FOR ME:

func isOdd(n: Int) -> Bool {
if n % 2 == 1 {
return true
} else {
return false
}
}

@SemennikovNA
Copy link

func isOdd(n: Int) -> Bool {
if n.isMultiple(of: 2) {
return false
} else {
return true
}
}

@ArmandaMendes
Copy link

func isOdd(n: Int) -> Bool {
if n % 2 == 1 {
return true
} else {
return false
}
}

isOdd(n: 5)

@Devavrat01
Copy link

func isodd(n: Int) -> Bool{
if (n % 2 == 0)
{
return true
} else
{
return false
}
}
var doorShouldopen = isodd(n: 5 )
print(doorShouldopen)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment