G
G
galithr2017-08-04 14:37:17
JavaScript
galithr, 2017-08-04 14:37:17

Which book or video course on linux to choose?

Recommend some good and up-to-date book or video course on linux....

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton Shvets, 2019-03-14
@Merrii

more or less decent js is written like this

const servPrice = {
  lin: 0,
  clean: 0,
};

/**
 * @param {HTMLInputElement[]} elements 
 * @param {HTMLInputElement} valueElement
 * @param {{lin: number; clean: number}} servPrice
 * @param {'lin'|'clean'} propName
 * @param {Function} done
 */
function act(elements, valueElement, servPrice, propName, done) {
  if (elements.length === 0) {
    return;
  }

  elements.forEach((element) => {
    element.addEventListener('change', () => {
      switch (element.value) {
        case 'Yes':
          servPrice[propName] = parseInt(valueElement.getAttribute("data-price"), 10);
          break;
        case 'No':
          servPrice[propName] = 0;
          break;
        default:
      }
      done();
    });
  });
}

act(
  [...document.querySelectorAll('input[name="Linen_Service"]')],
  document.querySelector('input[name="linen_price"]'),
  servPrice,
  'lin',
  renewDatas,
);

act(
  [...document.querySelectorAll('input[name="Cleaning_Service"]')],
  document.querySelector('input[name="cleaning_price"]'),
  servPrice,
  'clean',
  renewDatas,
);

only, of course, give the act function a more understandable name and describe what it does in a comment.
Plus, passing more than three parameters to a function is best done using an object and using destructuring.

V
Victor L, 2019-03-14
@Fzero0

well if so

let linServPrice = getValue("Linen_Service","linen_price"),
let cleanServPrice =getValue("Cleaning_Service","cleaning_price");

function getValue(Service,price){
if (document.querySelector(`input[name=${Service}]`)){
...
}
}

Z
zooks, 2017-08-04
@galithr

For beginners here:
https://stepik.org/course/73/syllabus

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question