# Code Cells

![](/files/SwcXWvqpHTRfvgZWhnSO)

**Code Cell** **works with information available in eva’s system that doesn’t depend on APIs. It also allows creating variables, that's why it provides immense advantages in a virtual agent flow creation process.**

Code cells are very useful in various scenarios, for example:

* In ecommerce, the Code cell would be responsible for almost the entire process, such as calculating the number of items or calculating the purchase, etc. Only the chosen products availability search and the finalization of the purchase would be in charge of the Service cell.&#x20;

Below, to insert in a Code cell, there is an example of code to calculate the value of the purchases in a shopping cart:

```
var total = 0.0;
if (visibleContext.shoppingCart != null && visibleContext.shoppingCart.items != null) {
    for (i in visibleContext.shoppingCart.items)
        total += i.price;
}
```

* You can also create a simple variable:

```
hiddenContext.myvar = 5;
```

* Or validate user login after a service call:

```
hiddenContext.logged = true
```

* In a game, you can simplify a lot the creation of quiz bringing together in a single cell all the questions and answers:

```
hiddenContext.questions = {
    "1": {
        "question":"What is the name of the first chatbot ever?",
        "answer":"ELIZA"
    },
    "2": {
        "question":"When was ELIZA created?",
        "answer":"1966"
    }
};.
```

Unlike the [Service Cell](https://docs.eva.bot/user-guide/using-eva/develop-your-bot/dialog-cells/service-cells), which connects data from a company via an API, Code Cell performs many activities (such as calculations and validation) without the need for this connection. This gives you the following advantages:

* Manipulate objects
* Anticipate executions and actions
* Perform services without the need for APIs
* Save time
* Reduce services costs

{% hint style="info" %}
**Important: With** [**Code** ](/_eva-3.4.1_1/using-eva/develop-your-bot/dialog-cells/code-cells.md)**and** [**Rule** ](/_eva-3.4.1_1/using-eva/develop-your-bot/dialog-cells/rule-cells.md)**cells, you can create** [**Variable Answers**](/_eva-3.4.1_1/using-eva/how-tos/creating-variable-answers-with-code-and-rule-cells.md)**.** 😉
{% endhint %}

### How can you create a Code Cell?

Just insert a code snippet in JavaScript as shown in the image below:

![Code cell field](/files/10r1KRETod6WvFUSAqKX)

You can use JavaScript’s variables (if you wanna know more about this language, [access this page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide)) and program any code in it, as long as it’s executable within 100 millisecond&#x73;**.**

The variables below can be used in eva on the Insert code field:

| Value          | Function                                                                                                                                 |
| -------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| input          | information that users write to the virtual agent and fed into eva                                                                       |
| opencontext    | information that is open to channels to alter its values                                                                                 |
| visiblecontext | information that is open to channels, but its values cannot be changed                                                                   |
| hiddencontext  | information that is closed to channels, being visible only to eva and the services called                                                |
| intents        | information registered in eva that means all about what the user wants to get out of the interaction                                     |
| entities       | information registered in eva that means knowledge repositories used by the virtual agent to provide personalized and accurate responses |
| channelType    | channel's type (if it's web, Facebook, Alexa, etc..)                                                                                     |
| channelName    | Channel's name registered in eva                                                                                                         |
| botName        |                                                                                                                                          |

<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs-conversational-ai.syntphony.com/_eva-3.4.1_1/using-eva/develop-your-bot/dialog-cells/code-cells.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
