en.javascript.info/1-js/4-data-structures/8-array-methods/1-add-class/task.md
2015-01-11 01:54:57 +03:00

23 lines
No EOL
824 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Добавить класс в строку
[importance 5]
В объекте есть свойство `className`, которое содержит список "классов" - слов, разделенных пробелом:
```js
var obj = {
className: 'open menu'
}
```
Создайте функцию `addClass(obj, cls)`, которая добавляет в список класс `cls`, но только если его там еще нет:
```js
addClass(obj, 'new'); // obj.className='open menu new'
addClass(obj, 'open'); // без изменений (класс уже существует)
addClass(obj, 'me'); // obj.className='open menu new me'
alert(obj.className); // "open menu new me"
```
P.S. Ваша функция не должна добавлять лишних пробелов.