Skip to content

Latest commit

 

History

History
51 lines (42 loc) · 1.22 KB

File metadata and controls

51 lines (42 loc) · 1.22 KB
chapter 5
pageNumber 30

If

En basit koşul ifadesi "if" ifadesidir ve sözdizimi (syntax) if (koşul) { bunu yap ... } şeklindedir. Koşul, süslü parantezlerin içindeki kodun yürütülmesi için doğru (true) olmalıdır. Örneğin, aşağıda açıklandığı gibi bir dizeyi test edebilir ve değerine bağlı olarak başka bir dizenin değerini ayarlayabilirsiniz.

let country = "France";
let weather;
let food;
let currency;

if (country === "England") {
  weather = "horrible";
  food = "filling";
  currency = "pound sterling";
}

if (country === "France") {
  weather = "nice";
  food = "stunning, but hardly ever vegetarian";
  currency = "funny, small and colourful";
}

if (country === "Germany") {
  weather = "average";
  food = "wurst thing ever";
  currency = "funny, small and colourful";
}

let message =
  "this is " +
  country +
  ", the weather is " +
  weather +
  ", the food is " +
  food +
  " and the " +
  "currency is " +
  currency;

console.log(message);
// 'this is France, the weather is nice, the food is stunning, but hardly ever vegetarian and the currency is funny, small and colourful'

{% hint style="info" %} Koşullar aynı zamanda iç içe de olabilir. {% endhint %}