# JavaScript решения

## Пример кода передачи файла на сторонний сервер:

```javascript
var fileUrl = "https://example.com/path/to/file.jpeg";
объект XMLHttpRequest
var xhr = new XMLHttpRequest();
xhr.open("POST", "/upload", true);
var formData = new FormData();
formData.append("file", fileUrl);

xhr.setRequestHeader("Content-Type", "multipart/form-data");
xhr.onload = function() {
  if (xhr.status === 200) {
    console.log("Файл успешно отправлен");
  } else {
    console.log("Ошибка отправки файла");
  }
};
xhr.send(formData);
```

## Пример кода для расчётов по дате рождения

URL для блока HTTP-запрос: <https://app.cleverapp.pro/api/v1/getMe?api\\_token=\\{{Ключ\\}}>

```javascript
var yearBirth = getContactVariable("Дата");
var year = yearBirth.substring(yearBirth.length - 4);
function digit (number) {
  var figures = "" + number
  var sum = 0

  for (var i = 0; i < figures.length; i++) 
    sum += +figures[i]

  return sum
}
year = digit(year);
if(year > 22){
  year = digit(year);
}
setContactVariable("Энергия", year) 
```

## Пример кода для бота с каталогом в кнопках

Для первого блока HTTP

```javascript
for (i = 1; i <= 100; i++) {
 deleteContactVariable("Кнопка "+i);
};
```

Для второго блока HTTP

```javascript
var total = response.data.meta.total;

for (i = 1; i <= total; i++) {
 var tovar = response.data.data[i-1].nazvanie;
 var cena = response.data.data[i-1].cena;
 setContactVariable("Кнопка "+i,
 tovar+" | "+cena+" ₽");
};
```

Для третьего блока HTTP

```javascript
var vibor = getContactVariable("выбор");
vibor = vibor.split(" |")[0];
setContactVariable("выбор", vibor);
```


---

# 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://help.cleverapp.pro/javascript-resheniya.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.
