Weekly questions to consider when creating your posts. These questions are a jumping off point to asking your own questions, pose new ideas, and provide explanations and examples backed by careful analysis. Apply class concepts, terms, and theories too. Refer to Assignment 12 for additional details.
- Why do we use if/else statements?
- What is the basic syntax of if/else if statements?
- What is the purpose of isNaN?
- How do we evaluate conditions if we have &&? What about ||?
- How are if statements different then else-if and else? Does an else statement take a Boolean Expression?
Ajibola Sode says
What is the basic syntax of if/else if statements?
The syntax of if/else if statements can be different across various programming languages, but the fundamental concept stays the same. It enables a program to run different code blocks based on specific conditions.
Dana Persaud says
Great answer! Additionally, the purpose of an if/else statement is to give a Boolean condition a choice of true/false. Usually they follow:
If (boolean condition) Then (consequent) Else (alternative) End If
Ajibola Sode says
Conditional logic is crucial in programming for enabling sophisticated decision-making within a program. It grants the ability to carry out varying actions contingent on different scenarios, thus fostering software that is both more versatile and reactive. Employing if/else if statements allows for the handling of decisions ranging from the straightforward, such as modifying the value of a variable when a certain condition is met, to the intricate, including navigating through various decision paths to execute particular operations based on multiple conditions.
Grasping the syntax and practical use of if/else if statements is essential for developers, as these elements form the core of logical thinking and the management of program flow in software engineering. They play a vital role in devising algorithms that are capable of responding to varying inputs and conditions, positioning them as an indispensable part of coding across various programming languages and development environments.
Darren Nolan says
Post
What is basic if/ else statements? If/else statements are different code blocks based on specific conditions. If else statements tell a program what if can and can’t do within what we are telling it to do. It makes your life easier when coding because if you have a statement in place you can type a certain word and it will do a bunch of stuff for you so it doesn’t take as long to make the code. An example would be if you said “20” was true and any other input would say false. This would safe a ton of time because you would manually have to go and do false for every single input that wasn’t 20 if you didn’t do the statement. Think about the last 2 coding assignments we did and we definitely used this a few times and if your an MIS major you use this on a daily basis and I bet it saves you a lot of time.
Zarmina Khan says
What is the purpose of isNaN?
The purpose of isNaN is that one it’s a function in javascript that stands for not is not a number. The purpose being that it determines whether or not a given value is a number or not. NaN is a special value in javascript because it represents the results of an operation that should return a number but doesn’t.
Ajibola Sode says
Hey Zarmina,
You’re right! The isNaN function is an important feature in JavaScript that helps ensure data accuracy and avoid calculation errors. It enables developers to handle incorrect or unexpected inputs in a graceful manner by identifying numbers and non-numbers. By recognizing NaN’s distinctive role in representing failed or indeterminate numerical operations, programmers can appreciate the significance of such checks in creating reliable coding practices.
Leanne Sheely says
Nice post! It’s interesting that it uses NaN for an error instead of just saying error or try again.
Madison Masino says
Hi Zarmina,
I enjoyed your post. One interesting thing I read about isNaN that isNaN(x) can also be replaced with a test for x !== x.
Leanne Sheely says
Why do we use if/else statements?
The if/else statements act as a helper for us. It makes it easier when writing code because if we have a certain criteria for something we can write a code to say a certain phrase or word when it meets the criteria and vise versa. An example of this would be you want it to say “true” when someone puts in “cat” but if they type anything else it will come up “false”. This makes your life easier because you can write just one code instead of making a code for every other word out there. This statement would be great for any type of guessing game. Using this would save you so much time. Try to now think about a time that you used something like this not as the person using it in their coding. I’m sure you can think of at least a couple of examples which just shows us why we should use it even more.
Hamida Akther says
Hi Leanne,
This is a great answer! Your definitions are easy to understand, and it’s concise. I agree if/else statements makes it easier to run code.
Corey Reagan says
Leanne,
I like how you kept this in Layman’s terms for me! Thank you for breaking it down and making it easier to understand for all of us who don’t write code for a living.
Jenna Oldroyd says
Hi Leanne,
Great explanation of why we use if/else statements; you made it easy to understand! If/else statements are conditional statements in JavaScript, which are used to perform different actions based on the condition in a quicker time frame.
Rachel Bard says
I will not lie, when I was first reading about if/else statements it kind of confused me…. Like a weird science hypothesis. It seems the more I repeat and read over what and if/else statement is the more i begin to understand them.
Georgios Zisis says
Hi Leanne,
I liked the example you have to describe an if/else statement. However, an important thing to note is how the code works. When the if statement is false, it then checks the else statement. If that statement is true the block is executed, but if the else statement is also false then both blocks are skipped.
Darren Nolan says
We have a a bunch of things on common good work.
Hamida Akther says
Why do we use if/else statements?
We use the if/else statements in JavaScript because If and Else statements allow you to run some code based on whether a condition is true or false. The if/else statement executes a block of code if a specified condition is true. If the condition is false, another block of code can be executed. The if/else statement is a part of JavaScript’s conditional statements, which are used to perform different actions based on different conditions. For example, if (something_is_true) { do_smething; } else { do_something_different; }. This is the most common conditional statement you will use in your code is the if/else statement or just the if statement. If you put your code in an HTML document and run it, with the expression you choose, example true, so the variable is initialized to true, so the “true” part of your if statement kicks in. Same thing goes for the false if the statement is false. For the if/else statement there are conditional operators used such as equal to, greater than, and less than to determine if/else statement is true or false.
Danylo Pidkova says
Hi Hamida,
Thank you for the detailed explanation. I think that if/else statements are powerful tools that add some decision-making power to our code. It’s like giving our program an instruction what to do based on different situations. When we write an if/else statement, we’re saying, Hey, if this condition is true, do this thing; otherwise, do something else.
Colin Johnson says
Hamida,
The example you provided effectively demonstrates how if/else statements work in practice, with one block of code executing if a condition is true, and another block executing if the condition is false. This flexibility is crucial for building dynamic and responsive applications that can adapt to different scenarios.
M'Kyah Graham says
This was a simple, but rather explanation. Coding can become very difficult, and in my opinion sometimes it’s hard to keep up. So simple, straightforward explanations like these are very helpful. Good work!
Mairaliz Negron says
Hi Hamida,
Your post was such a good breakdown and very detailed explanation. Your explanation is easy to understand and clear. Great work.
Danylo Pidkova says
How are if statements different then else-if and else? Does an else statement take a Boolean Expression?
if statements, else-if statements, and else statements are used to control the flow of a program based on specific conditions.
if statement checks a condition, and if it’s true, executes a block of code. If the condition is false, the block of code is skipped (not executed).
else-if statement allows to check for multiple conditions. If the previous if condition is false, it checks the next condition. If true, it executes the corresponding block of code.
else statement is executed if none of the previous conditions are true.
The else statement does not take a boolean expression. It executes if only all the if and else-if conditions above it are false.
Colin Johnson says
How do we evaluate conditions if we have &&? What about ||?
The logical operators && (AND) and || (OR) play crucial roles in evaluating conditions within expressions. When using &&, both conditions must be true for the overall expression to be true. If either condition is false, the entire expression evaluates to false. This operator is used to check multiple conditions simultaneously, ensuring that all conditions are met before proceeding with the code execution. || (OR) evaluates to true if at least one of the conditions is true. If both conditions are false, then the overall expression evaluates to false. This operator is useful when you want to execute a block of code if any of the specified conditions are true, providing flexibility in decision-making within your scripts.
Juan Delgado says
Hi Colin,
I enjoyed your discussion board since I was a little confused on this topic. I also thought it was very helpful in the way you described the topic of &&. This comment was very well thought out and I think you did a really good job with this explaining this topic.
Corey Reagan says
What is the purpose of isNaN?
The isNaN function is a built-in JavaScript function that stands for “is Not a Number.” Its primary purpose is to determine whether a given value is a valid number or not. This function is often used to validate input data and ensure that calculations are performed only on numeric values. The isNaN function serves a crucial role in JavaScript programming by helping to validate input data, prevent errors, and ensure the accuracy of calculations.
Lancelot Nyandoro says
Yep, Corey. It the cautioner behind the calculator with this function we have been able to move mountains in terms of with man has been able to do in 2oth century
Dana Persaud says
What is the basic syntax of if/else if statements?
If and else statements allow you to run some code based on if the condition is true or false. The statements usually vary across different languages but the basic syntax usually is:
if (boolean condition) Then (consequent) Else (alternative) End If
Jenna Oldroyd says
Why do we use if/else statements?
We use if/else statements as a part of JavaScript conditional statements. Conditional statements in JavaScript are used to perform different agents based on other conditions. If/else statements allow us to specify multiple conditions to be evaluated in a sequence. We will use the if/else statements to execute different statements on whether a condition is true or false. Using these statements is more efficient, as the computer has fewer steps to check if the condition is true. A secondary path of execution is provided when an if statement is false.
Cristina Valentin says
Hi Jenna,
Your explanation on if/else statements was thorough and gives a clear picture of why these are used.
Elena Grigoryan says
We use the if/else statements to act based on outlined conditions. This is of course very useful when coding becomes complex or long. “If” statement is quite basic, has only two outcomes, it identifies if the action is true or false. If/else statements can provide multiple outcomes with various values. “Else If” will state another condition and may provide a unique outcome. These statements become especially handy when there is a lot of data to evaluate.
Regan DeShazo says
Great post: I also Stated, just for a add on:
This branching capability is crucial for creating dynamic and responsive programs, as it allows developers to control the flow of their code and respond to various scenarios. Whether handling user input, processing data, or implementing complex algorithms, if/else statements empower programmers to create flexible and adaptable software that can respond intelligently to different situations.
Salvatore Marsico says
Hi Elena,
I liked reading your comment about if/else statements and how they act based on outlined conditions. Through this course, we learn various functions and codes to help us in our assignments, and learning these basic codes helps us further our understanding of coding.
Regan DeShazo says
Why do we use if/else statements?
If/else statements are fundamental constructs in programming that allow developers to introduce decision-making capabilities into their code. These statements enable a program to execute different blocks of code based on whether a specified condition evaluates to true or false. The if statement initiates this decision-making process by checking a condition, and if the condition is true, the associated block of code is executed. On the other hand, the else statement provides an alternative block of code to be executed if the initial condition evaluates to false. This branching capability is crucial for creating dynamic and responsive programs, as it allows developers to control the flow of their code and respond to various scenarios. Whether handling user input, processing data, or implementing complex algorithms, if/else statements empower programmers to create flexible and adaptable software that can respond intelligently to different situations.
Salvatore Marsico says
Hi Regan,
I enjoyed reading your post about If and else statements and how they are the basic fundamental constructs in programming. Learning these early on functions help programmers code easier and makes their lives much more simpler instead of writing lines of codes out.
Madison Masino says
Hi Regan,
I think your post is very informative on if/else statements. I did not know that the branching capability is crucial for creating dynamic and responsive programs, as it allows developers to control the flow of their code and respond to various scenarios.
Thanks for sharing that!
Salvatore Marsico says
We use if/else statements to see if codes, based on conditions, is true or false. For example, we can do if something is true, return this, if something is false, return this. If and else statements are very simple but they help the coder determine if statements are true or false. We can also add in operator symbols such as an equal sign, plus sign, or subtraction sign. Functions like this make coding much simpler then repeating the same code of lines and lines. The basic syntax of if and else if statements are if something is true then we return this value, but if something is false, we return a different value. The purpose of isNaN is to check whether a number if illegal or not. NaN stands for not a number so basically the function is checking if the value is not a number. This means it takes the value and converts it to a number to check.
Max Smith says
Hi Salvatore,
I thought you did a great job with the prompt. I specifically found helpful the explanation of where and how if/else statements can help coders work more efficiently. Finally, I liked how you explained how if/else statements present values, and if not, they present something else.
Max Smith says
What is the purpose of isNaN?
The isNaN() function determines whether a value is NaN (not-a-number). Specifically, the isNaN() function is designed to test if the number is the value NaN. The isNaN() function converts values to a number before testing them, and then returns true if a value is NaN.
Cristina Valentin says
What is the purpose of isNaN?
The purpose of isNAN is to indicate whether or not a value is a number. It will return true or false based on whether the value is not a number. True would be that the value is not a number, false would mean that the value is a number.
Eduard Lagutin says
Hey Cristina,
I like the way you described the purpose of isNAN. You were very clear and to the point. Great job.
Juan Delgado says
Why do we use if/else statements? We use if/else statements in this class to show if statements are true and false. We use this to code statements. This is like the Water Lane diagram that we did earlier in the semester. Every time there was a choice we made that a diamond. Two different arrows were pointing to time at a yes or a no. The variables for your if/else statements would be your rectangles after the yes or no arrows for the water lane diagrams. In this case with if/else statements the code would start with an if and then you would put in your variable for your code. Then, with the else statement you would put in another variable to your code to show that if you want your code to do something else. There are a bunch of different operators for if/else statements like != which means that the first expression is not equal to the second expression.
Mahbuba Ahmed says
Hi Juan
Your explanation effectively connects the concept of if/else statements in programming to the Water Lane diagram analogy. The comparison between the decision points in the diagram and the conditional branches in code adds clarity. The mention of operators like “!=” enhances the understanding of different conditions. Well insightful explanation overall.
Samir Lagouit says
Hi Juan,
I like the description you provide of if/else statements. I think it’s important that you highlighted the else statement in the way you did. It’s able to supplement your code in allowing it to do something else, and have the computer make decisions on it’s own.
Mahbuba Ahmed says
6a: How are if statements different then else-if and else? Does an else statement take a Boolean Expression?
Programmers use “if” statements as decision makers in programming; they check if certain conditions are true before taking appropriate actions if that condition holds true. By adding an “else-if”, programmers have more freedom in how they choose their actions. Ultimately, if the first condition in an “if” statement doesn’t hold, the “else-if” condition comes into play and runs the code to execute if that condition holds true. Otherwise, “else” takes over for further processing if none of the previous conditions work out. “Else” statements serve as a back up plan, should none of the previous conditions work out as expected. Although, these statements don’t directly evaluate Boolean expressions; they evaluate a Boolean expression to see if its evaluation evaluates true or false statements instead of directly taking up Boolean expressions directly. So in case all else fails, these work with either true or false scenarios.
Lesly Puma Vinansaca says
Hi Mahbuba
Your explanation of “if” and “else-if” statements helped me gain a bigger understanding of them. Great post!
Madison Masino says
What is the basic syntax of if/else if statements?
If/else statements allow you to run code based on if the statement is true or false. If the condition is true, the block of code inside the “if” statement is then executed.
Samir Lagouit says
Why do we use if/else statements?
The easiest way to explain why we use if/else statements, I feel like, is it’s how we communicate with the computer. The textbook used the example of us using true/false statements all day which is true, but only when you break it down in its simplest form. We wouldn’t communicate with people this way obviously, but this is how computers understand us.
If/else statements also are able to provide so much to a code. They have the ability to continue in options for as long as you go, allowing you to create very creative and elaborate scenarios. Without these statements especially with the else, we would be unable to create complex sentence structures, making codes unbearably long and exhausting. Imagine just consistent true/false statements, unable to lead anywhere. The other clear benefit is allowing the application to make decisions and choices. This is something likely not as common when computers were the size of rooms, but now is simple and taught in schools globally.
Cheyanne Kostaras-Nesbitt says
Hi Samir,
I really liked your explanation of the two functions. These two functions are, to me, the way the computer receives information we provide. I like how you compared it ti communication between the user and the computer. If we took our daily conversations and broke them down into true/false and if/else statements, we may sound strange in conversation, but the message would get through. It’s just the way people and computers communicate.
Zarmina Khan says
Samir, Understanding the if/else statement has been a doozy for me, but the way you have described it actually helped me understand the concept more. When computers were the size of rooms, I can only imagine the work that was getting done, imagine doing the same work we do in this class, but with those old computers, the time it would take.
Erica Griggs says
Hey Samir!
Really awesome breakdown of if/else statements!
Cheyanne Kostaras-Nesbitt says
What is the purpose of isNaN?
The purpose of the isNaN function is to test if a number is valid. NaN stands for “Not a Number”, so the function tests if the input is, in fact, not a number. This is helpful because it tests if the input is able to be performed. For example, a number divided by zero would be “NaN” and would return true for isNaN(x/0). This value can also be set to NaN. True numbers will return false. For example, isNaN(111) would result in “false”. For these functions, the argument entered is the number in question and the return is true if the argument is not a number and false if the number is a valid number.
Zarmina Khan says
Cheyanne, your example of the purpose of isNaN is very helpful for me. The way you have illustrated this for the reader, is very insightful which allows for better understanding on my end, Thanks!
Erica Griggs says
Hello Cheyanne,
Really good break down of the purpose of the isNaN function.
Erica Griggs says
“Navigating the Role of isNaN in MIS”
Hey guys! Let’s break down the mystery behind isNaN in our MIS journey. This JavaScript function is like a digital detective, and its main job is checking if something is not a number.
Now, why would we need a number detective? Picture this: you’re working with variables in your code, and sometimes, these variables might hold numbers, and other times, they could hold words or something else entirely. That’s where isNaN steps in.
Imagine having a variable, and you’re unsure if it’s packing a numerical punch or maybe just some text. You bring in isNaN to investigate. If it comes back as true, it means the variable isn’t a number; if it’s false, you’re dealing with a number.
In simple terms, isNaN is like our reliable number-checker in the coding realm, making sure everything stays in its numerical lane. It’s a handy tool for keeping our code in check!
Elena Grigoryan says
Thank you for such upbeat explanation! Great summary and example of isNan function being used!
Lesly Puma Vinansaca says
The isNaN function in JavaScript serves the purpose of determining whether a given value is a numeric value or not. When invoked, it returns true if the argument passed to it is “Not a Number” or cannot be converted into a valid numeric value, and false otherwise. This function is essential for validating user input, particularly in scenarios where numeric values are expected, such as form fields or mathematical calculations. However, it’s important to note that isNaN() may return unexpected results for certain non-numeric values like empty strings or objects, so careful consideration is required when using it in code. Nonetheless, isNaN remains a valuable tool for ensuring data integrity and handling numeric input validation in JavaScript applications.
Hadeer Saad says
I enjoyed your post, it was concise and easy to read. You made NaN in JavaScript easy to understand, Thank you!
M'Kyah Graham says
IF and ELSE statements is another shortcut in Java Script, meaning it makes our coding 100x easier during the process. If/else statements are conditional— if (or upon said condition) occurs, then (something) else will happen. When one thing is true, then something else will occur.
If/else codes are one of many that help to shorten the process of coding. Throughout the course of these past few weeks, I’ve come to understand coding as very deliberate. It is the control of the building blocks of all the technology we tend to use. Coding is starting from scratch, which can be very difficult. You have to be intentional, and have every sequence mapped out to achieve the desired effect on-screen. And the further you go on, the more complete it becomes. Which is why it’s so important to have shortcut red codes like if/else statements, NaN, loops and so many more!
Jorgelina Rodriguez says
hey! great statement ours were very similiar speaking on the needs of javascript
Hawa Barry says
Hi M’Kyah
Definitely agree on the deliberate aspects of coding. Coding from scratch is difficult, and shortcuts definitely help in that process.
Hadeer Saad says
Why do we use if/else statements?
We use if/else statements to contain the direction of a program based on particular conditions. These statements make running different blocks of code possible depending on whether a specific condition is actual or false. The if block is activated only if the condition is true, and the else block is activated if the condition is false. This allows the program to make choices adaptively, no matter the scenario. If/else statements are vital for creating malleable programs that can react to various inputs and conditions.
Briana Seidle says
Hey Hadeer,
You explained this topic perfectly! It’s simple and clear for understanding and retention.
Hadeer Saad says
What is the purpose of isNaN?
The isNaN function chooses whether a value is Not a Number. It returns a Boolean value. If the provided value is NaN, true. Suppose the value is a number, false. This function comes into handy when navigating user inputs or calculations, as it assists in instances where the result is not a number.
Eduard Lagutin says
What is the basic syntax of if/else if statements?
The most basic syntax of if/else statements is:
If this is true do this action
If the above statement isn’t true do/ check for this action
If none of the above statements are true do this action.
You can get more complicated with it because you can have as many if/ else statements in a function.
Maurice Chism says
Yes I agree that you can as many as you wish. The one thing about the if/else statement is that else does not have to be used in the statement because the if can be determined as true, it will complete.
Briana Seidle says
What is the purpose of isNaN?
The purpose of isNAN is meant to determine if an object is valid. If a value is not a number, then the isNAN returns true. In other words, the isNAN function determines whether the value is NAN by first converting the value to a number if necessary. It can also be referred to as Number.isNAN. It serves a vital role in Javascript by helping validate the data inputted, ensure accurate calculations, and reduce/prevent errors.
Lancelot Nyandoro says
What is the purpose of isNaN?
isNaN function in JavaScript is used to determine whether a value is NaN (Not-a-Number). It is kind of like the mathematic police of coding. In its most basic form, for every wrong mathematical result, it gives a true or false statement to the answer before showing you the answer. And the true or false claim to see if the answer could even be possible. isNaN can be employed to check the validity of user input, ensuring that only numeric values are processed in mathematical computations or comparisons. This type of tool is usually used in games of chance such pick a number, it would tell you if you were high or low, hot or cold to the number in questions. In purest from, it is numbers game.
Hadeer Saad says
I like how you broke the NaN function down and made it easy to understand. Also, I like the comparison you used to the mathematic police of coding.
Hawa Barry says
Hi Lancelot,
I really liked your explanation of NaN and when to use it. I feel like a lot of when to use is missing in instructions of using JS, so thanks!
Mairaliz Negron says
Why do we use if/else statements?
– If/ else statements let us run code based on whether a condition is true or false. We use if/else statements because they help computers to make decisions. The if/else statements let the program take different paths based on what the conditions are. It’s useful for dealing with different situation. Depending on the behavior of someone, certain actions will be triggered while others are skipped over.
Jorgelina Rodriguez says
In programming, if/else statements are used to regulate the flow of execution in response to specific conditions. These statements enable us to assess if a condition is true or false and use that information to make decisions within our code. The code inside the if block is run if the condition evaluates to true; if not, the code inside the else block, if it exists, is executed. If/else statements allow us to write more responsive and dynamic programs that can adapt to various inputs or conditions. They let us to incorporate branching logic, which lets our programs change and react in response to evolving circumstances or user input. Furthermore, if/else statements are fundamental programming constructs that are necessary for creating algorithms and logic-driven apps.
Maurice Chism says
What is the purpose of isNaN?
IsNan in Javascript is a method that returns true if a value is Not a Number. This method before it tests it will convert it to a number if necessary. This is used to determine whether an argument to a function is arithmetically processable. This will also assist in giving a error when a value is given that is represented as a number. This helps both the user and the coder because it can produce a response that is one which is not the desired outcome for the input.
Georgios Zisis says
How are if statements different then else-if and else? Does an else statement take a Boolean Expression?
The general idea of if and else statements is they allow you to run some code based on whether a condition is true or false. If statements in a general sense are the more basic condition for this. If statements evaluate a Boolean expression and if the expression is false, then the code inside the if block is skipped. The else if statement checks for multiple conditions. If the if condition is false, then the program continues onto the else condition. If the else condition is true the block is executed, but if it is false the block is skipped. The else condition is used when none of the if or else if conditions are met. There is no condition to be met and a default choice is chosen when the previous conditions are false. Else statements do not require a Boolean expression, because there is no condition to check. When there is no condition to check then Boolean Expression is not needed.
Dylan Milano says
Hi Georgios,
Your explanation of if statements, else-if statements, and else statements effectively distinguishes between these conditional constructs in programming. You provide a clear overview of how if statements evaluate a Boolean expression and execute code based on a true or false condition, while else-if statements are used for multiple conditional checks and else statements serve as a default option when previous conditions are not met.
Corey Reagan says
What is the purpose of isNaN?
The isNaN function is a built-in JavaScript function that stands for “is Not a Number.” Its primary purpose is to determine whether a given value is a valid number or not. This function is often used to validate input data and ensure that calculations are performed only on numeric values. The isNaN function serves a crucial role in JavaScript programming by helping to validate input data, prevent errors, and ensure the accuracy of calculations. Additionally, isNaN is a valuable tool in situations where developers need to differentiate between numerical and non-numerical values. For instance, in sorting algorithms where comparing and sorting numerical values is crucial, isNaN can be used to filter out non-numeric entries from the comparison process. Moreover, isNaN is essential in data validation and error handling processes. By incorporating isNaN checks in code, developers can spot potential bugs or issues early on and handle them appropriately. This helps improve the overall reliability and robustness of the software. The purpose of the isNaN function is to ensure the integrity and accuracy of numeric values in a program, prevent errors caused by unexpected input, and facilitate efficient data processing and manipulation. By incorporating isNaN checks in code, developers can enhance the quality and reliability of their applications while providing a better user experience.
Leanna Paul says
Hi Corey, I enjoyed reading your post. I responded to the same questions but I failed to include any real world examples. Your example helped me to further understand when isNaN may come into effect. Good job.
Ereny Abousaif says
Hi Corey
Reading your content was enjoyable. I answered the same questions, but I omitted any instances from the actual world. I now have a better understanding of when isNaN may be applicable thanks to your example. Well done.
Dylan Milano says
Conditional statements like if/else are fundamental in programming as they help control the flow of a program based on certain conditions. We use if/else statements to execute specific blocks of code when certain conditions are met. This allows for branching logic where different paths are taken depending on the evaluation of conditions.
The basic syntax of if/else if statements involves using the keywords if, else if (optional), and else (optional) followed by a condition inside parentheses and a block of code to execute. The syntax helps structure the logic flow by evaluating conditions sequentially and executing corresponding code blocks.
Leanna Paul says
The JavaScript isNaN function is used in programming to determine whether a given value is “Not a Number” (NaN). The isNaN function returns “true” if the value passed to it is NaN, and “false” if the value is a valid number or can be converted into one. It is particularly useful when working with operations or functions that involve numerical calculations, such as parsing user input or performing mathematical computations.
Daniel Taylor says
thank you for your feedback and research on this Leanna as it helped me understand what NaN truly was as this was a new function I discovered in this course. It amazes me how things like this can really improve the understanding of coding in JavaScript and all the skills it requires to understand to make any coding project a successful one.
Ereny Abousaif says
What is the purpose of isNaN?
When determining if a given value is Not a Number in JavaScript, the isNaN method automatically transforms the value to a number if necessary before running the test. When determining if an input supplied to a function is appropriate for arithmetic operations, this functionality is especially helpful. This makes it easier to recognize and manage situations in which an input is meant to be a number but isn’t represented as one. This proactive approach helps the developer and the user by eliminating unexpected consequences and making it easier to identify input problems.
Hadeer Saad says
Why do we use if/else statements?
We use if/else statements in programming to control the flow of our code based on certain conditions. These statements allow us to execute different blocks of code depending on whether a condition is true or false.
One primary reason for using if/else statements is to create decision-making logic within our programs. By evaluating conditions using if/else statements, we can make our code more dynamic and responsive to different scenarios or user inputs.
Furthermore, if/else statements enable us to handle alternative outcomes or branches in our code execution. For example, we might use an if/else statement to check if a user is logged in, and if not, display a login prompt instead of proceeding to restricted content.
In summary, if/else statements are essential for creating logic, making decisions, and controlling the flow of our programs based on specific conditions, thus enhancing the flexibility and functionality of our code.
Hadeer Saad says
What is the purpose of isNaN?
The `isNaN()` function in JavaScript stands for “is Not a Number.” Its purpose is to determine whether a value is a numeric value or not. It returns `true` if the value passed to it is not a number, and `false` otherwise.
The primary purpose of `isNaN()` is to perform type checking and validation when working with numerical data in JavaScript. It is commonly used to prevent unexpected behavior or errors when performing mathematical operations or conversions on variables that may not contain valid numeric values.
For example, `isNaN()` can be used to validate user input in form fields to ensure that only numeric values are accepted. It can also be used to handle edge cases where numerical data may be missing or improperly formatted.
Overall, `isNaN()` helps developers write more robust and reliable code by providing a simple and effective way to check for non-numeric values in JavaScript applications.
Kerri McGuckin says
Hi Hadeer,
This is a great overview of “isNaN()” this function seems like a very powerful capability while writing Javascript as it sets apart values from being numerical or not. However, I do not know if I will ever write codes advanced enough to the point where I need a function like this.
Kerri McGuckin says
When writing Javascript code, there are often times when you will ask the user for a prompt or to answer a question. If their question is the correct answer, you will want to give them a different alert than if their answer is wrong. This is a scenario where you could possibly use an if/else statement. If and Else statements allow you to run some code based on whether a condition is true or false. This can really include any expression that evaluates to true or false, for instance you could ask the user for their height, maybe only heights over a certain number of inches will be correct because we are trying to see if they can ride on a roller coaster – and we could set any height < a certain number of inches to be incorrect. This would look something like "if the person is over 48" then they can ride a roller coaster, else they cannot" (but pretend that is coded correctly). it would read something like…
if (rider over 48) {
// they can ride roller coaster
} else {
//they cannot ride roller coaster
}
Hawa Barry says
To expand on coding, if/else statements provide the ability to run code based on whether a condition is true or false. There are several operators that are either relational or logical that go into the if/else statements. “If” refers to a condition being true, and when it comes with “else” it refers to alternative options or simply false. With serveral “elses”, this is when alternative options are introduced. These can also be nested to simulate more complex situations. These if/else statements are pretty straightforward as well, I just think it’s a matter of knowing when this is preferable compared to other forms of code. Seeing more combined use of code is helpful though to discern the usage.
Daniel Taylor says
What is the purpose of isNaN?
After reading multiple articles to gain more knowledge of what “isNaN” is cause this is something I never heard of before. After researching, it seems to pair vey well with JavaScript as it is a value in JavaScript used to represent an undefined or unrepresentable value in JavaScript. This allows us to understand there is an error in the coding and that we must find out what it is and fix it to make the coding a success.