1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- // *************1*************
- var person = [
- a = {surname: 'A', name: 'aa', fathername: 'Aa', country: 'Ukraine',},
- b = {surname: 'B', name: 'bb', country: 'Polsha',},
- c = {surname: 'C', name: 'cc', country: 'Vengria',}
- ];
- // *************2*************
- for (var items of person) {
- console.log(items);
- }
- // *************3*************
- for (var i = 0; i < person.length; i++) {
- console.log('name: ' + person[i].name);
- console.log('surname: ' + person[i].surname);
- }
- // *************4*************
- for (var i = 0; i < person.length; i++) {
- if ('fathername' in person[i]) {
- person[i].fullName = prompt('enter full name',)
- }
- }
- console.log(person);
- // *************5*************
- let json = JSON.stringify(person);
- console.log(json);
- // *************6*************
- let d = '{"surname":"D","name":"dd"}';
- d = JSON.parse(d);
- person.push(d);
- console.log(person);
- // *************7*************
- var str = "<table border='1'><tr><td>Name</td><td>Surname</td></tr>";
- for (let i = 0; i < person.length; i++) {
- str += ' <tr><td>${person[i].name}</td><td>${person[i].surname}</td></tr>'
- }
- str += "</table>";
- console.log(str);
- document.write(str);
- // *************8*************
- function avg2(a, b) {
- if (isNaN(a) || isNaN(b)) {
- console.log('there must be numbers');
- }
- else {
- return ((a + b) / 2);
- }
- }
- console.log(avg2(4, 6));
- // *************9*************
- function sum(a, b, c) {
- if (isNaN(a)) {
- return b + c
- }
- if (isNaN(b)) {
- return a + c
- }
- else if (isNaN(c)) {
- return a + b
- }
- else if (isNaN(b) && isNaN(c) && isNaN(a)) {
- return 'error';
- }
- else return a + b + c;
- }
- console.log(sum(1, 'fdrhzrht', 5));
- // *************10*************
- function intRandom(a, b) {
- if (b === undefined) {
- b = a;
- a = 0;
- }
- a = Math.ceil(a);
- b = Math.floor(b);
- return Math.round(Math.random() * (b - a + 1)) + a;
- }
- console.log(intRandom(5));
- // *************11*************
- function sum(...arguments) // параметры собираются в массив params
- {
- var sum = 0;
- for (let i = 0; i < arguments.length; i++) {
- sum += arguments[i];
- }
- return sum;
- }
- console.log(sum(3, 45, 7, 3, 4, 5, 6, 7));
|