forked from engindemirog/javaScriptStarterKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.js
More file actions
178 lines (134 loc) · 3.84 KB
/
functions.js
File metadata and controls
178 lines (134 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
function addToCart(productName="elma",quantity) {
console.log(productName,quantity)
}
addToCart("yumurta",10)
console.log("sevgi")
let sayHello = () =>{
console.log("hello sevgi")
}
sayHello()
let sayHello2 =function() {
console.log("hello sevgi")
}
sayHello2();
function addToCart2(productName,quantity,unitPrice) {
}
addToCart2("elma",5,10)
addToCart2("armut",2,10)
let product1={productName:"elma",unitPrice:10,quantity:5}
function addToCart3(product) {
console.log("ürün : "+product.productName+" miktar :"+product.quantity+" birim fiyat : "+product.unitPrice)
}
// object tanımladık
addToCart3(product1)
let product2={productName:"elma",unitPrice:10,quantity:5}
let product3={productName:"elma",unitPrice:10,quantity:5}
product2=product3
product2.productName="KARPUZ"
console.log(product3.productName)
let sayi1=10
let sayi2=20
sayi1=sayi2
console.log(sayi1)
// obje ve array referans tip
// değer tip:
function addToCart4(x) {
console.log(x)
}
let products=[
{productName:"elma",unitPrice:10,quantity:5},
{productName:"armut",unitPrice:10,quantity:5},
{productName:"kiraz",unitPrice:10,quantity:5}
]
addToCart4(products)
function add(number1,number2) {
console.log(number1+number2+number2)
}
add(20,50)
function add2(...numbers) {
console.log(numbers)
}
add2(1,2,5,6,5,5,55,5)
// REST KONUSU BU ŞEKİLDE
// rest her zaman fonksiyonun sonuna yazılır.
function add3(...numbers) {
let total=0
for (let i = 0; i < numbers.length; i++) {
total=total+numbers[i]
}
console.log(total)
}
add3(1,5,2,2,1000,2,2,2,2)
// math.max in içerisine array i ayırmadan gönderemeyiz. ...sayilar şekilde yazılması içerisinde ayrılmasını sağlar.
let sayilar=[10,20,50,30,47]
console.log(...sayilar)
console.log(Math.max(...sayilar))
//-----------------------------------------------------------------------------
// GİRİLEN SAYILARIN ASAL OLUP OLMADIĞINI BULAN FONKSİYON
function AsalSayiBul(...sayilar) {
for (let i = 0; i < sayilar.length; i++) {
let kontrol = 0
for (let j = 2; j < sayilar[i]; j++) {
if (sayilar[i]%j==0)
kontrol++
}
if(kontrol==0)
console.log(sayilar[i] + ":" + "asaldır.")
else
console.log(sayilar[i] + ":" + "asal değildir.")
}
}
AsalSayiBul(2,5,2,8,75,137,4)
//Parametre olarak girilen iki sayının arkadaş sayılar olup olmadığını bulan programı yazınız.
function FriendNumbers(sayi1,sayi2) {
let sayi1Bolen =0
let sayi2Bolen=0
for (let i = 0; i < sayi1; i++) {
if (sayi1%i==0)
sayi1Bolen=sayi1Bolen+i
}
for (let k = 0; k < sayi2; k++) {
if (sayi2%k==0)
sayi2Bolen=sayi2Bolen+k
}
if (sayi1Bolen==sayi2 && sayi2Bolen==sayi1 ) {
console.log(sayi1 + " ve "+sayi2 +" arkadaş sayılardır.")
console.log(sayi1Bolen)
console.log(sayi2Bolen)
} else {
console.log(sayi1 + " ve "+sayi2 +" arkadaş sayı değillerdir.")
console.log(sayi1Bolen)
console.log(sayi2Bolen)
}
}
FriendNumbers(220, 284)
FriendNumbers(2620, 2924)
FriendNumbers(3,5)
//1000'e kadarki tüm mükemmel sayıları listeleyen programı yazınız.
// bazı pozitif tam sayıların pozitif bölenleri toplamı, sayının kendisinin iki katına eşittir. Bu tür sayılara “mükemmel sayı” denir.
function PerfectNumbers() {
for (let i = 0; i < 1001; i++) {
let bolenToplam=0
for (let k = 0; k < i+1; k++) {
if(i%k==0)
bolenToplam=bolenToplam+k
}
if(i*2==bolenToplam)
console.log(i+" sayısı mükemmel sayıdır.")
}
}
PerfectNumbers()
//1000'e kadarki tüm asal sayıları listeleyen programı yazınız.
function asalSayilar2() {
for (let i = 0; i < 1001; i++) {
let kontrol=0
for (let k = 2; k < i; k++) {
if(i%k==0)
kontrol=kontrol+1
}
if(kontrol==0)
console.log("Asal Sayılar:")
console.log(i)
}
}
asalSayilar2()