123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- /* a */
- function a(text){
- alert(text)
- }
- a("Привет!")
- /* cube */
- function cube(number){
- return number ** 3
- }
- let result = cube(prompt('Enter a number'))
- console.log(result)
- /* avg2 */
- function avg2(a1, b1) {
- return (a1 + b1) / 2
- }
- let a1 = +prompt('Enter a number')
- let b1 = +prompt('Enter a number')
- avg2(a1, b1)
- /* sum3 */
- function sum3(a2 = 0, b2 = 0, c2 = 0) {
- let sum1 = (a2 + b2 + c2)
- return sum1
- }
- sum3(a2, b2, c2)
- /* intRandom */
- function intRandom(a3, b3) {
- let random = Math.random()* (b3-a3) + a3
- return Math.round(random)
- }
- let a3 = +prompt('Enter a number')
- let b3 = +prompt('Enter a number')
- intRandom(a3, b3)
- /* greetAll */
- function greetAll() {
- let greetAll1 = " "
- for (let i = 0; i < arguments.length; i++) {
- greetAll1 += " " + arguments[i] + ","
- }
- alert("Hello, " + greetAll1);
- }
- greetAll("superman", "Spiderman", "Бетмен")
- /* sum */
- function sum(a4, b4, c4) {
- let sum = 0;
- for (let i = 0; i < arguments.length; i++) {
- sum += arguments[i];
- }
- return sum
-
- }
- a4 = +prompt('Enter a number')
- b4 = +prompt('Enter a number')
- c4 = +prompt('Enter a number')
- sum(a4, b4, c4)
- /* Union */
- function aSample(){
- a("Привет!")
- }
-
- function cubeSample(){
- cube(5)
- }
-
- function avg2Sample(){
- avg2(2, 2)
- }
-
- function sum3Sample(){
- sum3(1, 2, 3)
- }
-
- function intRandomSample(){
- intRandom(2,10)
- }
-
- function greetAllSample() {
- greetAll('Superman')
- }
-
- function sumSample(){
- sum(1,4,7)
- }
-
-
- var sample = prompt("Введите название задания")
- switch (sample.toLowerCase()){
- case "a": aSample()
- break;
- case "cube": cubeSample()
- break;
- case "avg2": avg2Sample()
- break;
- case "sum3": sum3Sample()
- break;
- case "intRandom": intRandomSample()
- break;
- case "greetAll": greetAllSample()
- break;
- case "sum": sumSample()
- break;
- }
- /* Union declarative */
- let unionDeclarative = {
- a(){
- a("Привет!")
- },
- cube(){
- cube(5)
- },
- avg2(){
- avg2(2, 2)
- },
- sum3(){
- sum3(1, 2, 3)
- },
- intRandom(){
- intRandom(2,10)
- },
- greetAll(){
- greetAll('Superman')
- },
- sum() {
- sum(1, 4, 7)
- }
- }
|