123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- // a ==============================================================================
- function a(someStr){
- alert(someStr)
- }
- // a("Привет")
- // a("Как дела?")
- // a("Как погода?")
- // cube ==============================================================================
- function cube(ourNum){
- let result
- result = ourNum**=3
- console.log(result)
- }
- // cube(17)
- // avg2 ==============================================================================
- function avg2(firstNum,secondNum){
- let result
- result = (firstNum + secondNum)/2
- console.log(result)
- }
- // avg2(7,10)
- // sum3 ==============================================================================
- function sum3(firstNum,secondNum,thirdNum){
- let result
-
- if(thirdNum===undefined){
- thirdNum=0
- }
- if(secondNum===undefined){
- secondNum=0
- }
- result = (firstNum + secondNum + thirdNum)
- console.log(result)
- }
- // sum3(1,2,3)
- // intRandom ==============================================================================
- function intRandom (minNum, maxNum){
- let result
- if(maxNum===undefined){
- maxNum=minNum
- minNum=0
- }
- result = Math.round(Math.random() * (maxNum - minNum ) + minNum)
- console.log(result)
- }
- // intRandom(2,15)
- // intRandom(-1,-1)
- // intRandom(0,1)
- // intRandom(10)
- // greetAll ==============================================================================
- function greetAll() {
- let result = ''
- for(let i=0; i<arguments.length; i++){
- result+=arguments[i]+', '
- }
- result = result.slice(0,-2)
- alert('Hello '+result)
- }
- // greetAll('Kate','Vlad','Marina','Sveta','Andrey','Cat','Superman')
- // sum ==============================================================================
- function sum(){
- let result = 0
- for(i=0; i<arguments.length; i++){
- result +=arguments[i]
- }
- console.log(result)
- }
- // sum(1)
- // sum(2)
- // sum(10,20,40,100)
- // Union ==============================================================================
- function aChoice(){
- a("Привет")
- a("Как дела?")
- a("Как погода?")
- }
- function cubeChoice(){
- cube(17)
- }
- function avg2Choice(){
- avg2(7,10)
- }
- function sum3Choice(){
- sum3(1,2,3)
- }
- function intRandomChoice (){
- intRandom(2,15)
- intRandom(-1,-1)
- intRandom(0,1)
- intRandom(10)
- }
- function greetAllchoice(){
- greetAll('Kate','Vlad','Marina','Sveta','Andrey','Cat','Superman')
- }
- function sumChoice(){
- sum(1)
- sum(2)
- sum(10,20,40,100)
- }
- let taskChoice = prompt('Введите название задания')
- switch(taskChoice.toLowerCase()) {
- case 'a': aChoice()
- break;
- case 'cube': cubeChoice()
- break;
- case 'avg2': avg2Choice()
- break;
- case 'sum3': sum3Choice()
- break;
- case 'intrandom': intRandomChoice()
- break;
- case 'greetall': greetAllchoice()
- break;
- case 'sum': sumChoice()
- break;
- }
- // Union declarative ==============================================================================
- let taskChoiceTwo = prompt('Введите название задания')
- const functionObj = {
- 'a': aChoice,
- 'cube': cubeChoice,
- 'avg2': avg2Choice,
- 'sum3': sum3Choice,
- 'intrandom': intRandomChoice,
- 'greetall': greetAllchoice,
- 'sum': sumChoice
- }
- functionObj[taskChoiceTwo.toLowerCase()]()
- // ============================================================================================================================================================
|