# TypeError: Cannot read property 'add' of undefined

**URL:** <https://forums.fusetools.com/t/typeerror-cannot-read-property-add-of-undefined/6230>\
**Category:** General\
**Created:** [February 9, 2016, 1:27pm UTC](https://forums.fusetools.com/t/typeerror-cannot-read-property-add-of-undefined/6230 "2016-02-09T13:27:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![chiztorismo](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/chiztorismo/32/587_2.png) [@chiztorismo](https://forums.fusetools.com/u/chiztorismo)\
**Post date:** [February 9, 2016, 1:27pm UTC](https://forums.fusetools.com/t/typeerror-cannot-read-property-add-of-undefined/6230/1 "2016-02-09T13:27:55Z")

</div>

I am trying to create a simple app that lets you create a market list

this is my code for the UI

```auto
<App Theme="Basic">
    <JavaScript File="JS/app.js"/>
    <DockPanel>
        <StatusBarBackground Dock="Top" />
        <DockPanel>
            <Panel>
                <LinearNavigation ux:Name="_appNav" Easing="CircularInOut" Duration="0.5" />
                <Page ux:Class="AppPage">
                    <EnteringAnimation>
                        <Move X="-1" Duration="-0.5" />
                    </EnteringAnimation>
                    <ExitingAnimation>
                        <Move X="1" Duration="0.5" />
                    </ExitingAnimation>
                </Page>
                <Rectangle ux:Class="Save" Fill="#D7440D" CornerRadius="0" />

                <AppPage>
                    <StackPanel Alignment="Top" Background="#7B8395">
                        <Text Value="JustSaying" TextColor="#F6ED46" FontSize="40" Alignment="Center" />
                    </StackPanel>

                    <StackPanel Alignment="TopCenter" Margin="10,100,0,0">
                        <Each Items="{note_content}">
                            <Text Value="{list}" />
                        </Each>
                        <!-- <Text Value="{note_content}" /> -->
                    </StackPanel>

                    <StackPanel Alignment="Bottom">
                        <Grid ColumnCount="2" Background="#E6E6E6" Alignment="Bottom">
                            <TextInput Margin="0,10,-90,0" PlaceholderColor="#9C9C9C" PlaceholderText="Enter text here" Opacity="1" Background="#E6E6E6" Value="{note_entered}"/>
                            <Save Margin="100,0,0,0" Clicked="{send}">
                                <Text Value="Save" Alignment="Center"/>
                            </Save>
                            <WhileKeyboardVisible>
                                    <Move Y="-1" RelativeTo="Keyboard" />
                            </WhileKeyboardVisible>
                        </Grid>
                    </StackPanel>
                </AppPage>
            </Panel>
        </DockPanel>
    </DockPanel>
</App>

```

This is my JS

```auto
// all variables are declered here
var Observable = require("FuseJS/Observable");
var def_value = Observable({list: "Market list is empty"});
var note_entered = Observable();

function yap(){
    // body...
    if (note_entered.value){
        def_value.value = "";
        def_value = def_value.add({list: note_entered.value});
        note_entered.value = "";
        return def_value;
    }
    else{
        def_value.value = "";
        def_value = def_value.add({list: "You cant post empty values"});
        return def_value;
    }
};

module.exports = {
    note_content : def_value,
    note_entered: note_entered,
    send : yap,
};

```

I realise that when I enter a text for the first time, it add shows up on my view,

But when I add another value and click the send button it says this as the error

```auto

ERROR: 
    Name: TypeError: Cannot set property 'value' of undefined
    Error message: Uncaught TypeError: Cannot set property 'value' of undefined
    File name: /Users/chizom/Documents/AndroidProject/JustSaying/JS/app.js
    Line number: 14
    Source line: def_value.value = "";
    JS stack trace: TypeError: Cannot set property 'value' of undefined
        at yap (/Users/chizom/Documents/AndroidProject/JustSaying/JS/app.js:14:19)

```

what do you think I am doing wrong or not implementing

---

<div class="post-metadata">

**Author:** ![Kristian\_Hasselknipp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/kristian_hasselknipp/32/549_2.png) [@Kristian\_Hasselknipp](https://forums.fusetools.com/u/Kristian_Hasselknipp)\
**Post date:** [February 9, 2016, 1:31pm UTC](https://forums.fusetools.com/t/typeerror-cannot-read-property-add-of-undefined/6230/2 "2016-02-09T13:31:05Z")

</div>

You have an error in line 14 of app.js…

What does the code around line 14 look like?

---

<div class="post-metadata">

**Author:** ![chiztorismo](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/chiztorismo/32/587_2.png) [@chiztorismo](https://forums.fusetools.com/u/chiztorismo)\
**Post date:** [February 9, 2016, 1:34pm UTC](https://forums.fusetools.com/t/typeerror-cannot-read-property-add-of-undefined/6230/3 "2016-02-09T13:34:00Z")

</div>

![file](https://s3.us-east-2.amazonaws.com/fuse-legacy-forum-assets/Ic2RlLnyFfAa-legacy-files-tPQYoSeEKtV55QiX-ezT37qBaxYtuem7wXpojA3wM.png)

---

<div class="post-metadata">

**Author:** ![Kristian\_Hasselknipp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/kristian_hasselknipp/32/549_2.png) [@Kristian\_Hasselknipp](https://forums.fusetools.com/u/Kristian_Hasselknipp)\
**Post date:** [February 9, 2016, 1:36pm UTC](https://forums.fusetools.com/t/typeerror-cannot-read-property-add-of-undefined/6230/4 "2016-02-09T13:36:40Z")

</div>

Why are you assigning def\_value to the result of def\_value.add in line 15 and 21?

`def_value = def_value.add({list: note_entered.value});`

Try just

```auto
def_value.add({list: note_entered.value});

```

---

<div class="post-metadata">

**Author:** ![chiztorismo](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/chiztorismo/32/587_2.png) [@chiztorismo](https://forums.fusetools.com/u/chiztorismo)\
**Post date:** [February 9, 2016, 1:41pm UTC](https://forums.fusetools.com/t/typeerror-cannot-read-property-add-of-undefined/6230/5 "2016-02-09T13:41:12Z")

</div>

`it worked perfectly` I am all smile. Thanks to you and all the TEAM FUSE. I LOVE YOU ALL

---

<div class="post-metadata">

**Author:** ![Jake\_Taylor](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/jake_taylor/32/512_2.png) [@Jake\_Taylor](https://forums.fusetools.com/u/Jake_Taylor)\
**Post date:** [February 9, 2016, 1:43pm UTC](https://forums.fusetools.com/t/typeerror-cannot-read-property-add-of-undefined/6230/6 "2016-02-09T13:43:14Z")

</div>

Glad we could help!

Side note, any reason why you’re returning the `def_value` `Observable` from `yap`?

---

<div class="post-metadata">

**Author:** ![Jake\_Taylor](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/jake_taylor/32/512_2.png) [@Jake\_Taylor](https://forums.fusetools.com/u/Jake_Taylor)\
**Post date:** [February 9, 2016, 1:48pm UTC](https://forums.fusetools.com/t/typeerror-cannot-read-property-add-of-undefined/6230/7 "2016-02-09T13:48:45Z")

</div>

Also you shouldn’t need to set `def_value`'s `value` to `""`; you should be fine with just:

```auto
function yap() {
  if (note_entered.value){
    def_value.add({list: note_entered.value});
    note_entered.value = "";
  }
  else{
    def_value.add({list: "You cant post empty values"});
  }
}

```

Note the semicolon after the function definition is also not needed 🙂

---

<div class="post-metadata">

**Author:** ![Kristian\_Hasselknipp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/kristian_hasselknipp/32/549_2.png) [@Kristian\_Hasselknipp](https://forums.fusetools.com/u/Kristian_Hasselknipp)\
**Post date:** [February 9, 2016, 2:33pm UTC](https://forums.fusetools.com/t/typeerror-cannot-read-property-add-of-undefined/6230/8 "2016-02-09T14:33:04Z")

</div>

Glad it worked 😃
