File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < title > Document</ title >
6+ </ head >
7+ < body >
8+ < script >
9+ function sum ( a , b ) {
10+ return a + b
11+ }
12+
13+ function dif ( a , b ) {
14+ return a - b
15+ }
16+
17+ function div ( a , b ) {
18+ return a / b
19+ }
20+
21+ function mul ( a , b ) {
22+ return a * b
23+ }
24+
25+ function mathOperation ( arg1 , arg2 , operation ) {
26+ switch ( operation ) {
27+ case '+' :
28+ return sum ( arg1 , arg2 )
29+ break
30+ case '-' :
31+ return dif ( arg1 , arg2 )
32+ break
33+ case '/' :
34+ return div ( arg1 , arg2 )
35+ break
36+ case '*' :
37+ return mul ( arg1 , arg2 )
38+ break
39+ }
40+ }
41+
42+ alert ( mathOperation ( 4 , 3 , '+' ) )
43+ alert ( mathOperation ( 4 , 3 , '-' ) )
44+ alert ( mathOperation ( 4 , 3 , '/' ) )
45+ alert ( mathOperation ( 4 , 3 , '*' ) )
46+ </ script >
47+ </ body >
48+ </ html >
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < title > Document</ title >
6+ </ head >
7+ < body >
8+ < script >
9+ 'use strict'
10+ function getResultString ( Num ) {
11+ let str_num = String ( Num )
12+ let last_char = str_num . charAt ( str . length - 1 )
13+ let pre_last_char
14+ if ( str_num . length > 1 ) {
15+ pre_last_char = str_num . charAt ( str . length - 2 )
16+ }
17+ //если от 10 до 19 то рублей
18+ if ( pre_last_char == '1' ) {
19+ return Num + ' рублей'
20+ }
21+ //если остальные варианты то проверяем
22+ switch ( last_char ) {
23+ case '2' :
24+ case '3' :
25+ case '4' :
26+ return Num + ' рубля'
27+ case '1' :
28+ return Num + ' рубль'
29+ default :
30+ return Num + ' рублей'
31+ }
32+ }
33+
34+ let str = prompt ( "введите сумму" )
35+ alert ( getResultString ( str ) )
36+
37+ </ script >
38+ </ body >
39+ </ html >
You can’t perform that action at this time.
0 commit comments