index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Required
  2. let letters = [];
  3. let str = 'Backend As A Service'.split(' ');
  4. letters = str.map (
  5. function ( currentValue ) {
  6. return currentValue.substr(0,1)
  7. }
  8. )
  9. console.log(letters);
  10. let newStr = letters.join('');
  11. console.log(newStr);
  12. // Additionally
  13. let date = new Date();
  14. let string = 'Неверный тип данных'
  15. function check(val) {
  16. if ((typeof val) === 'number')
  17. return date;
  18. else
  19. return string;
  20. }
  21. console.log(check(5));
  22. console.log(check('jghgh'));
  23. // Additionally
  24. function testUserText ( userText ) {
  25. return userText.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#x27;');
  26. }
  27. function insertUserText ( userText ) {
  28. var x = document.createElement ( 'div' )
  29. x.innerHTML = testUserText ( userText )
  30. document.body.appendChild ( x )
  31. }
  32. insertUserText (`<svg/onLoad = 'document.write("Looser");
  33. document.body.style.backgroundColor = "black";
  34. document.body.style.color = "red";
  35. document.body.style.fontSize = "50px"
  36. document.body.style.fontWeight = "bold";
  37. document.body.style.textAlign = "center";
  38. document.body.style.paddingTop = "45%";'>`)