1+ //Task-1
2+ function returnObject ( value ) {
3+ let newObject = {
4+ name : value
5+ } ;
6+ return newObject ;
7+ } ;
8+
9+ let someObject = returnObject ( 'Oleg' ) ;
10+ console . log ( someObject ) ;
11+
12+
13+ //Task-2
14+ function toUpperCase ( obj ) {
15+ let newObjeckToUpperCase = {
16+ [ 'name' ] : obj . name . toUpperCase ( )
17+ } ;
18+ return newObjeckToUpperCase ;
19+ } ;
20+
21+ const objectWithName = { name : 'privet kak dela' } ;
22+ console . log ( toUpperCase ( objectWithName ) ) ;
23+
24+
25+ //Task-3
26+ let arr = [ ] ;
27+ arr [ 0 ] = 'privet' ;
28+ arr [ 1 ] = 'poka' ;
29+ arr [ 2 ] = 'zdrastvuite' ;
30+
31+ function addToArray ( arrParam , newElem ) {
32+ arr [ arr . length ] = newElem ;
33+ return arr ;
34+ } ;
35+
36+ addToArray ( arr , 34 ) ;
37+ console . log ( arr ) ;
38+ addToArray ( arr , 55 ) ;
39+ console . log ( arr ) ;
40+
41+
42+ //Task-4
43+ function simpleObjectGenerator ( one , two , three ) {
44+ let object = {
45+ argument1 : one ,
46+ argument2 : two ,
47+ argument3 : three
48+ } ;
49+ return object ;
50+ } ;
51+
52+ var userNames = [ { name : 'Egor' } , { name : 'Katya' } , { name : 'Vera' } ] ;
53+
54+ console . log ( simpleObjectGenerator ( 'protocol' , { url : '22' } , 8000 ) ) ;
55+ console . log ( simpleObjectGenerator ( 77 , userNames , 'privet kak dela chto novogo' . toUpperCase ( ) ) ) ;
56+
57+
58+ //Task-5
59+ var myName = { name : 'Oleg' } ;
60+
61+ function addNameToUser ( newKey , newValue , userName ) {
62+ let objectToUser = {
63+ [ newKey ] : newValue
64+ } ;
65+ if ( 'name' in userName ) {
66+ objectToUser . name = userName . name ;
67+ return objectToUser ;
68+ } else {
69+ return objectToUser ;
70+ } ;
71+ } ;
72+
73+ console . log ( addNameToUser ( 'family' , '%Lustenko%' , myName ) ) ;
74+ console . log ( addNameToUser ( 'name' , 'privet Pasha' , { } ) ) ;
75+
76+ console . log ( myName ) ;
77+
78+
79+
80+ // Super-1
81+ function fizzBuzz ( num ) {
82+ if ( num % 3 == 0 && num % 5 == 0 ) {
83+ return console . log ( 'FizzBuzz' ) ;
84+ } else if ( num % 5 == 0 ) {
85+ return console . log ( 'Buzz' ) ;
86+ } else if ( num % 3 == 0 ) {
87+ return console . log ( 'Fizz' ) ;
88+ } else {
89+ return console . log ( num ) ;
90+ } ;
91+ } ;
92+
93+ fizzBuzz ( 1 ) ; // 1
94+ fizzBuzz ( 2 ) ; // 2
95+ fizzBuzz ( 3 ) ; // 'Fizz'
96+ fizzBuzz ( 5 ) ; // 'Buzz'
97+ // ...
98+ fizzBuzz ( 15 ) ; // 'FizzBuzz'
99+ fizzBuzz ( 21 ) ; // 'Fizz'
100+
101+
102+
103+ // Super-2
104+
105+ function super2 ( arg1 , arg2 , arg3 , callback ) {
106+ let arrSuper2 = [ arg1 , arg2 , arg3 ] ;
107+ callback ( arrSuper2 ) ;
108+ } ;
109+
110+ let callbackSuper = function ( arg ) {
111+ console . log ( arg ) ;
112+ } ;
113+
114+ super2 ( 1 , 'января' , 2018 , callbackSuper ) ;
115+
116+
117+
118+ // Classwork problem task
119+
120+ function promptNumber ( promptText ) {
121+ let number = parseInt ( prompt ( promptText , 'Число' ) ) ;
122+ if ( isNaN ( number ) ) {
123+ return promptNumber ( promptText )
124+ } else {
125+ return number ;
126+ } ;
127+ } ;
128+
129+ let num1 = promptNumber ( 'Введите первое число' ) ;
130+ let num2 = promptNumber ( 'Введите второе число' ) ;
131+ console . log ( num1 + num2 ) ;
0 commit comments