خلاصه “Java Script by Behzad Farhadi – Session 07 – Part 2”
مقدمه
در این جلسه، بهزاد فرهادی ادامهی آموزش جاوا اسکریپت خود را با توضیح نحوه نوشتن توابعی آغاز میکند که میتوانند شرایط مختلف را بررسی کرده و نتایج را مطابق با آنها چاپ کنند. این جلسه بر آموزش نحوه ایجاد توابعی تمرکز دارد که میتوانند بررسی کنند که آیا یک عدد مثبت، منفی یا صفر است و همچنین نحوه ارزیابی نمره آزمون یک دانشآموز.
نکات اصلی
ساخت یک تابع برای بررسی عدد (مثبت، منفی، صفر)
بهزاد نحوه نوشتن یک تابع به نامcheckNumber
را نشان میدهد که یک عدد را به عنوان ورودی میگیرد و بررسی میکند که آیا آن عدد مثبت، منفی یا صفر است.- تابع از دستور
if
استفاده میکند تا بررسی کند آیا عدد بزرگتر از صفر (مثبت)، کوچکتر از صفر (منفی) یا برابر با صفر است. - نتیجه با استفاده از
console.log
چاپ میشود و نشان میدهد که عدد مثبت، منفی یا صفر است. - همچنین نحوه فراخوانی تابع با ورودیهای مختلف (مثل
checkNumber(10)
یاcheckNumber(-1)
) را نشان میدهد.
- تابع از دستور
مثال با نمره آزمون
سپس بهزاد یک تابع برای بررسی نمره آزمون یک دانشآموز نشان میدهد تا مشخص کند که آیا قبول شده یا مردود.- تابع
checkExamScore
نمره آزمون را به عنوان ورودی میگیرد و بررسی میکند که آیا نمره 60 یا بیشتر است. - اگر نمره 60 یا بیشتر باشد، تابع پیام “قبول شدید” را چاپ میکند. اگر کمتر از 60 باشد، پیام “متأسفانه رد شدید” چاپ میشود.
- سپس تابع را طوری اصلاح میکند که وقتی نمره دقیقاً 60 باشد، پیام ویژهای مانند “قبول شدید به صورت مشروط” نمایش دهد.
- تابع
استفاده از
else if
برای شرایط متعدد
بهزاد توضیح میدهد که چگونه از دستورelse if
برای افزودن شرایط بیشتر به تابع استفاده میشود. به عنوان مثال، زمانی که نمره دقیقاً 60 باشد، یک شرط اضافی اضافه میشود تا پیام ویژهای برای نمره 60 چاپ کند.
نتیجهگیری
در این قسمت از جلسه، بهزاد فرهادی به طور مؤثر نحوه نوشتن توابعی برای ارزیابی شرایط ساده مانند بررسی مثبت/منفی/صفر بودن و منطق قبول/مردود شدن بر اساس نمره آزمون را نشان میدهد. همچنین بر اهمیت استفاده از دستورات if
، else
و else if
برای مدیریت شرایط متعدد در جاوا اسکریپت تأکید میکند.
Detailed Summary of “Java Script by Behzad Farhadi – Session 07 – Part 2”
Introduction
In this session, Behzad Farhadi continues his JavaScript tutorial by explaining how to write functions that can handle different conditions and output results accordingly. The session focuses on teaching how to create functions that can check whether a number is positive, negative, or zero, as well as how to evaluate a student’s exam score.
Main Points
Creating a Function to Check Numbers (Positive, Negative, Zero)
Behzad demonstrates how to write a function calledcheckNumber
that takes a number as an argument and checks whether it is positive, negative, or zero.- The function uses the
if
statement to check if the number is greater than zero (positive), less than zero (negative), or equal to zero. - The output is displayed using
console.log
, indicating whether the number is positive, negative, or zero. - He also shows how to call the function with different inputs (e.g.,
checkNumber(10)
orcheckNumber(-1)
).
- The function uses the
Example with an Exam Score
Next, Behzad demonstrates a function for checking a student’s exam score to determine if they passed or failed.- The function,
checkExamScore
, takes an exam score as input and checks whether it is greater than or equal to 60. - If the score is 60 or above, the function prints “You passed”. If it is below 60, it prints “Unfortunately, you failed”.
- He then modifies the function to handle the case where the score is exactly 60, printing a conditional message: “You passed conditionally”.
- The function,
Using
else if
for Multiple Conditions
Behzad explains how to useelse if
to add more conditions to the function. For instance, when checking if a score is exactly 60, an additional condition is added to print a special message for a score of 60.
Conclusion
In this part of the session, Behzad Farhadi effectively demonstrates how to write functions to evaluate simple conditions like positive/negative/zero checks and pass/fail logic based on an exam score. He also emphasizes how to use if
, else
, and else if
statements to handle multiple conditions in JavaScript.
