# Chapter 3 mini exercise 1

**URL:** <https://forums.kodeco.com/t/chapter-3-mini-exercise-1/50956>\
**Category:** Swift Apprentice\
**Created:** [September 27, 2018, 10:26am UTC](https://forums.kodeco.com/t/chapter-3-mini-exercise-1/50956 "2018-09-27T10:26:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdotflow22](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/mdotflow22/32/81494_2.png) [@mdotflow22](https://forums.kodeco.com/u/mdotflow22)\
**Post date:** [September 27, 2018, 10:26am UTC](https://forums.kodeco.com/t/chapter-3-mini-exercise-1/50956/1 "2018-09-27T10:26:31Z")

</div>

“Create a constant called myAge and set it to your age. Then, create a constant named isTeenager that uses Boolean logic to determine if the age denotes someone in the age range of 13 to 19.”

my logic:

let myAge = 32

let isTeenager = 13…\<19

When I try to compare myAge to isTeenager I get this error message: Binary operator ‘==’ cannot be applied to operands of type ‘Int’ and ‘Range’

my question:  
how do you denote someones age in a specified range without using the … syntax? Any help is greatly appreciated. Thanks!

---

<div class="post-metadata">

**Author:** ![syedfa](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/syedfa/32/101500_2.png) [@syedfa](https://forums.kodeco.com/u/syedfa)\
**Post date:** [September 29, 2018, 4:30am UTC](https://forums.kodeco.com/t/chapter-3-mini-exercise-1/50956/2 "2018-09-29T04:30:24Z")

</div>

@mdotflow22 Thanks very much for your question!

You can try something like this:

```
if (13 ..< 19).contains(myAge) {
   isTeenager = true
} else {
   isTeenager = false
}

```

I hope this helps!

All the best!

---

<div class="post-metadata">

**Author:** ![h1i2j3](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/h1i2j3/32/100893_2.png) [@h1i2j3](https://forums.kodeco.com/u/h1i2j3)\
**Post date:** [September 29, 2018, 5:52am UTC](https://forums.kodeco.com/t/chapter-3-mini-exercise-1/50956/3 "2018-09-29T05:52:39Z")

</div>

> [@mdotflow22](#):
>
> When I try to compare myAge to isTeenager I get this error message: Binary operator ‘==’ cannot be applied to operands of type ‘Int’ and ‘Range’

Based on your logic:

Constant `myAge` is of type _Int_.  
Constant `isTeenager` is of type _Range_.

You will get that error message if you try to evaluate a bool from comparing the two different types to see if they are equal (==)

```auto
myAge == isTeenager // error

```

* * *

> [@mdotflow22](#):
>
> how do you denote someones age in a specified range without using the … syntax? Any help is greatly appreciated. Thanks!

In addition to @syedfa 's solution 👍 , another way could be to compare `myAge` to `isTeenager`’s upper and lower bounds of it’s range.

`isTeenager` will resolve to true if both (&&) it’s conditions are true

```auto
let myAge = 32 // 32
let isOlderThan12 = myAge >= 13 // true
let isYoungerThan20 = myAge <= 19 // false

let isTeenager = isOlderThan12 && isYoungerThan20 // false

```

This can written more ‘swiftly’ like this:

```auto
let myAge = 32 // 32
let isTeenager = myAge >= 13 && myAge <= 19 // false

```

Cheers!  
Rebecca

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [March 13, 2019, 2:26am UTC](https://forums.kodeco.com/t/chapter-3-mini-exercise-1/50956/4 "2019-03-13T02:26:50Z")

</div>

Closed on March 13, 2019, 2:26am UTC

This topic was automatically closed after 166 days. New replies are no longer allowed.
