%% Getting Help % This example shows how to display help for MATLAB using the 'help' command. % % Copyright 2018 The MathWorks, Inc. %% % The command 'help' lists all primary help topics in the Command Window. % The format 'help name' displays the help text for the functionality specified by name, such as a function, method, class, or variable. disp('Display help for the ''close'' function.') disp('>> help close') help close
Timestamp 12:00 Checking if number is odd or even: let num = 232; let result = num % 2 ; if (result ===0){ console.log("num is even")} else console.log("num is odd") // output: num is even
FInding if a number is Even or Odd , time stamp 12:00 function oddEven(num) { if(num % 2 === 0) { num = 'even'; }else { num = 'odd'; } return num; } console.log(oddEven(4));
let x=4; if(x%2===0){ console.log("even"); } else{ console.log("odd"); } there is difference between % and / operators. % modulas to find remainder and / division to find result after simple division in maths.
Sir I know the series is very helpful and informative but there is a huge delay in videos. For completing the actual js client part that the series aimed at, it will take 4-5 months i think, please consider that Sir :)
Are you going to create videos on C language too, it will be very helpful for me and my college mate, cause I have problem to learn it, and the way you taught java last Sunday was phenomenal
I found a simpler way, you can only compare the remaining two values: let num1 = 15; let num2 = 10; let num3 = 20; if (num1 > num2 && num1 > num3) { console.log("num1 is greatest"); } else if (num2 > num3) { console.log("num2 is greatest"); } else { console.log("num3 is greatest") } console.log("Exit")
correct but for better result remove unintentional case // function to check even or odd number function evenOdd(num){ //remove unintentional case if(typeof num === "number"&&Number.isInteger(num)) { if(num%2===0){ console.log("even"); } else{ console.log("odd"); } } else{ console.log("not a integer number"); } }
So if num1 > num2 is the condition but it is not satisfied then we can use both a console.log after } or else and console.log with a new set of 2 curly brackets?
I love Javascript its like reading code from wordpress and after Js, if U know what I mean, U will say,omg f wp who can working with that, u havnt freedom, with JS U have freedom enough. I start love JS . Its my secend best friend :P
Hello Sir, I tried this on my console and what I observed that if I put ; at the end of if (result); then its still showing the output as num1 is greater though it is false. kindly suggest why this is happening. let num1 = 3; let num2 = 4; let result = num1 > num2; if(result); console.log("Num 1 is greater"); console.log("Bye.."); output : [Running] node "c:\Users\Desktop\js\IfElse.js" Num 1 is greater Bye.. [Done] exited with code=0 in 0.166 seconds
function oddEven(num) { if(num % 2 === 0) { num = 'even'; }else { num = 'odd'; } return num; } console.log(oddEven(4)); you should create function for any number
nice , let num=4.5; if(typeof num === "number"&&Number.isInteger(num)) {if(num%2===0){ console.log("even"); } else{ console.log("odd"); }} else{ console.log("not a integer number"); } suppose user can give num is string or float then how to deal for good programming practice remove unintentional cases
my assignment: I took hours racking my head on displaying the different variable calculations in a single block, but I couldn't,😉🙂 it was fun. let num1 = 10 / 2; let num2 = 9 / 2; let num3 = 7 / 2; if (num1 % 1) { console.log("odd"); } else { console.log("even"); }; if (num2 % 1) { console.log("odd"); } else { console.log("even"); }; if (num3 % 1) { console.log("odd"); } else { console.log("even"); };
// sir ur example has a bug if 2 no. r equal then?? // Assignment let num = 8; if (num%2===0){ console.log("number is even") } else{ console.log("number is odd") }
working fine you can use like this as let num=4; if(typeof num === "number"&&Number.isInteger(num)) {if(num%2===0){ console.log("even"); } else{ console.log("odd"); }} else{ console.log("not a integer number"); }
correct to check even and odd but not good way to write you declare lots of variable for simple work. let x=4; if(x%2===0){ console.log("even"); } else{ console.log("odd"); }
I can only imagine how hard it is to explain things for a beginner to understand when you have explained same concepts earlier in other videos. I would have always be like: 'As I said earlier....'
when I try this it gives me an error saying "ReferenceError: prompt is not defined". even though I replaced "Enter a number: " with 8(any number for example) in the first line. Is prompt supposed to be an in-built JS thing or do I have to define prompt like we define any variable?
Sometimes, you leave out brackets around if statements: function round(n, upperBound, lowerBound) { if (n > upperBound) || (n < lowerBound) { // Not enough brackets here!
Hi Naveen, What if, I will write code like this: let num1 = 9; let num2 = 9; let result = num1 > num2; if (result){ console.log("num1 is greater"); } else { console.log("num2 is greater"); } Here the output is showing num2 is greater, could you explain it?
in the " If " statement, you check that " num1 greater than num2 ". As all of us know, 9 is not greater than 9. So it returns false and then it goes to the else block, because your comparison returns false. The " else " block doesn't means the opposite ( greater smaller ) but it means everything which won't be accepted to your comparison
you are missing one condition for equality if(num1>num2) console.log('num1 is greater than num2'); else if(num1===num2) console.log('num1 is equal to num2'); else console.log('num1 is less than num2');
function evenOdd(num){ //remove unintentional case if(typeof num === "number"&&Number.isInteger(num)) {if(num%2===0){ console.log("even"); } else{ console.log("odd"); }} else{ console.log("not a integer number"); } } this way
Find out given number is even or off Let num = 2 If (num%2 === 0) { Console.log("given number is even"); }//% says 2/2 remainer is 0 else { Console.log("given number is off"); }
// why use of semicolon is important in javascript ? // semicolon is used to separate the statements in javascript and avoid the errors in javascript that are not expected by the user . since, javascript doesnot generate any error and if we use semicolon it prevent our code from error
since num2 is equal to num3 that's why else if condition fail and condition come to else part now use like that else if(num2>=num1&&num2>=num3) console.log("num2 is greatest");
i like your series in general sir, but you should have told us how to take inputs before gioin into these stuff.... is FRUSTRATING not knowing how to get input and doing these operations , it makes programming boring, i already have experience in python
working fine but you can use like that also for better result this conditon fail for string and float use like this if(typeof num === "number"&&Number.isInteger(num)) {if(num%2===0){ console.log("even"); } else{ console.log("odd"); }} else{ console.log("not a integer number"); }
n=4
If(n%2==0)
console. log(evennumber) ;
Else if(n%2==1)
console. log( odd number) ;
Else
Console(end the program)
evennumber
always use === instead of this ==
%% Getting Help
% This example shows how to display help for MATLAB using the 'help' command.
%
% Copyright 2018 The MathWorks, Inc.
%%
% The command 'help' lists all primary help topics in the Command Window.
% The format 'help name' displays the help text for the functionality specified by name, such as a function, method, class, or variable.
disp('Display help for the ''close'' function.')
disp('>> help close')
help close
Timestamp 12:00
Checking if number is odd or even:
let num = 232;
let result = num % 2 ;
if (result ===0){
console.log("num is even")}
else console.log("num is odd")
// output: num is even
The ternary operator would be a nice addition to learning how if-else statements work.
FInding if a number is Even or Odd , time stamp 12:00
function oddEven(num) {
if(num % 2 === 0) {
num = 'even';
}else {
num = 'odd';
}
return num;
}
console.log(oddEven(4));
absolutely correct
// Given assignment
let num1 = 3
if ((num1 % 2) == 0) {
console.log("num1 is even")
} else {
console.log("num1 is odd")
}
correct but use semicolon after every statement
Wow sir you finally changed the contrast thank you soooooo much❤️ we love your content👍
"yeee" lololol IDK why that made me laugh so hard. I love the way you teach....thank you so much.
You made if else conditions complicated for beginners in other videos its showcased very simply and clearly.
Question for Video length 9:20 minutes.. The logical operator to you use would be &&
//Logical operators are used to determine the logic between variables or values.
/*
Operator Description
&& logical and
|| logical or
! logical not
*/
Clean and nice
let n = 12;
if(n/2 === 0){
console.log("even")
};
console.log("odd")
let x=4;
if(x%2===0){
console.log("even");
}
else{
console.log("odd");
}
there is difference between % and / operators. % modulas to find remainder and / division to find result after simple division in maths.
Sir I know the series is very helpful and informative but there is a huge delay in videos. For completing the actual js client part that the series aimed at, it will take 4-5 months i think, please consider that Sir :)
Impressed Sir here is your assignment
let num1=25
if(num1%2==0){
console.log('(num1 is even');
}
else{
console.log('num1 is odd');
}
Are you going to create videos on C language too, it will be very helpful for me and my college mate, cause I have problem to learn it, and the way you taught java last Sunday was phenomenal
very very basics that no one is telling but are. that's awesome!! plz make more videos for this playlist
@@user-ii2ek8hf1r if teacher call something to student out of love.
Just take it with joy 😊. Or you can simply unsubscribe.
I found a simpler way, you can only compare the remaining two values:
let num1 = 15;
let num2 = 10;
let num3 = 20;
if (num1 > num2 && num1 > num3) {
console.log("num1 is greatest");
}
else if (num2 > num3) {
console.log("num2 is greatest");
}
else {
console.log("num3 is greatest")
}
console.log("Exit")
let a = prompt("enter a value");
if(a%2 == 0){
console.log("even");
}
else{
console.log("odd");
}
If(n%2==0) //We are checking Number is divided exactly by 2 or not
console.log("even");
else
console.log("odd");
if condition is true then it should print even, your console.log needs to be swapped
@@theCodesConnection thanks👍 updated
correct but for better result remove unintentional case
// function to check even or odd number
function evenOdd(num){
//remove unintentional case
if(typeof num === "number"&&Number.isInteger(num))
{
if(num%2===0){
console.log("even");
}
else{
console.log("odd");
}
}
else{
console.log("not a integer number");
}
}
5:35 is Eye Opening to me 😍😍😍😍.
9:25 its very tough for me to guess 😞
let a=10;
if(a%2==0)
console.log(a,'is a even number')
else
console.log(a," is a odd number.")
Let a =int(input("enter a number u needed"))
It is === not ==
@@Namakarana but its also work
So if num1 > num2 is the condition but it is not satisfied then we can use both a console.log after } or else and console.log with a new set of 2 curly brackets?
4:35 i copied it exactly same and checked it multiple time but num1 is greater is not printing and it say process finished with exit code 0
it worked when i put = with >
9:21 logical AND(&& )
I love Javascript its like reading code from wordpress and after Js, if U know what I mean, U will say,omg f wp who can working with that, u havnt freedom, with JS U have freedom enough.
I start love JS .
Its my secend best friend :P
Hello Sir,
I tried this on my console and what I observed that if I put ; at the end of if (result); then its still showing the output as num1 is greater though it is false. kindly suggest why this is happening.
let num1 = 3;
let num2 = 4;
let result = num1 > num2;
if(result);
console.log("Num 1 is greater");
console.log("Bye..");
output :
[Running] node "c:\Users\Desktop\js\IfElse.js"
Num 1 is greater
Bye..
[Done] exited with code=0 in 0.166 seconds
Remove al ; semicolon,this will help
After if (result) remove ;
You are ending the if statement there itself if you keep ;
let num1 = 3;
let num2 = 4;
let result = num1 > num2;
if(result); //
I/p:-
Let n=12;
If(n%2==0)
{
Console.log(number is even);
}
else
{
console.log(number is odd);
}
O/p:-number is even.
function oddEven(num) {
if(num % 2 === 0) {
num = 'even';
}else {
num = 'odd';
}
return num;
}
console.log(oddEven(4));
you should create function for any number
if(num1%2==0){
console.log("Its an even number");
}
else{
console.log("Its a odd number");
}
if (num1 % 2 === 0){
console.log("Even Number")
}
else
console.log("Odd")
if (num2 % 2 === 0){
console.log("Even Number")
}
else
console.log("Odd")
if (num3 % 2 === 0){
console.log("Even Number")
}
else
console.log("Odd")
Sir, I created a separate if else for each input
Let num = 15;
If(num % 2 === 1){console.log(‘num is an odd number’)}
Else{console.log(‘num is an even number);}
9:21 I should use and "&&" operator
whats the difference between system.out.printIn() and console.log()
Assignment
let num1 = 2
if (num1 % 2 == 0) {
console.log("num1 is even")
}
else {
console.log("num1 is odd")
}
nice ,
let num=4.5;
if(typeof num === "number"&&Number.isInteger(num))
{if(num%2===0){
console.log("even");
}
else{
console.log("odd");
}}
else{
console.log("not a integer number");
}
suppose user can give num is string or float then how to deal for good programming practice remove unintentional cases
i learned basics of c already, js is heaven comparably to c 😹
at 9.18 the operator we use is &&
my assignment:
I took hours racking my head on displaying the different variable calculations in a single block, but I couldn't,😉🙂 it was fun.
let num1 = 10 / 2;
let num2 = 9 / 2;
let num3 = 7 / 2;
if (num1 % 1) {
console.log("odd");
}
else {
console.log("even");
};
if (num2 % 1) {
console.log("odd");
}
else {
console.log("even");
};
if (num3 % 1) {
console.log("odd");
}
else {
console.log("even");
};
let a=3; // to check whether number is odd or even
if(a%2===0)
console.log("the number is even");
else
console.log("the number is odd");
correct to check
Finding number is even or odd.
Let a=prompt("enter a value")
If(a%2===0){
Console.log("even");
}else{
Console.log("odd");
}
prompt is saying "not defined", using number instead of prompt got me the result perfectly.
The answer is:
let num = 10;
if(num % 2 == 0){
console.log('The number is even number')
}
else{
console.log('The number is odd number')
}
The number is divided by 2 that is even or its odd number
If the condition num1%2==0 that is even or that is odd number
// sir ur example has a bug if 2 no. r equal then??
// Assignment
let num = 8;
if (num%2===0){
console.log("number is even")
}
else{
console.log("number is odd")
}
I m bit confused about what lang to chooce
i sugggest choose java and javascript both.
"Java Script say:its your choice! " :D :D
3:42
let num=5
if (num%2)
console.log("Number is odd")
else
console.log("Number is even")
working fine
you can use like this as
let num=4;
if(typeof num === "number"&&Number.isInteger(num))
{if(num%2===0){
console.log("even");
}
else{
console.log("odd");
}}
else{
console.log("not a integer number");
}
let num1 = 86
if (num1 % 2 == 0){
console.log("the given number is even")
}
else
console.log("the given number is odd")
console.log("Bye...")
Sir it would really be halpful if u start a tutorial on Data science
let x = 3;
let y = 2;
let result = x%y;
if (result === 0)
console.log(" Number is even")
else
console.log("Number is odd")
correct to check even and odd but not good way to write you declare lots of variable for simple work.
let x=4;
if(x%2===0){
console.log("even");
}
else{
console.log("odd");
}
Let num = 5;
Let result= num % 2;
If (result===0)
Console.log(num, "is an even number");
else
Console.log(num, "is an odd number");
//Task
let num1 = 10,
num2 = 4,
num3 = 7;
function isCheck(ele) {
return ele % 2 == 0;
}
isCheck(num1) ? console.log("Even") : console.log("Odd");//Even
isCheck(num2) ? console.log("Even") : console.log("Odd");//Even
isCheck(num3) ? console.log("Even") : console.log("Odd");//Odd
I can only imagine how hard it is to explain things for a beginner to understand when you have explained same concepts earlier in other videos.
I would have always be like: 'As I said earlier....'
let num = parseInt(prompt("Enter a number: "));
if (number %2 == 0)
console.log("Number is Even");
else
console.log("Number is Odd');
when I try this it gives me an error saying "ReferenceError: prompt is not defined". even though I replaced "Enter a number: " with 8(any number for example) in the first line. Is prompt supposed to be an in-built JS thing or do I have to define prompt like we define any variable?
Sir but when I try using else it says unexpected token
Sometimes, you leave out brackets around if statements:
function round(n, upperBound, lowerBound) {
if (n > upperBound) || (n < lowerBound) { // Not enough brackets here!
9:12 AND operator
//Assignment
let num=99;
if(num%2==0){
console.log("num is even number")
}
else{
console.log("num is odd number");
}
really enjoying
Hi Naveen,
What if, I will write code like this:
let num1 = 9;
let num2 = 9;
let result = num1 > num2;
if (result){
console.log("num1 is greater");
}
else
{
console.log("num2 is greater");
}
Here the output is showing num2 is greater, could you explain it?
It's completely false case
Both are equal num1==num2
u should put num1 == num2 since both the numbers are the same
in the " If " statement, you check that " num1 greater than num2 ". As all of us know, 9 is not greater than 9. So it returns false and then it goes to the else block, because your comparison returns false. The " else " block doesn't means the opposite ( greater smaller ) but it means everything which won't be accepted to your comparison
you are missing one condition for equality
if(num1>num2)
console.log('num1 is greater than num2');
else if(num1===num2)
console.log('num1 is equal to num2');
else
console.log('num1 is less than num2');
I am a mechanical engg with zero programming kngle
thank you very much!
9:25 AND &&
I guess I'm the 1st commenter
// check no is either odd or even
let x = 146;
if(x%2===0){
console.log(x is even)
}
else{
console.log(x is odd)
}
// output: x is even
Thank you very much
// it is a even or odd number
let num = 145
if (num%2==0){
console.log("it is a even number ", num)
}
else{
console.log("it is a odd number", num)
}
How to give functions in conditions
function evenOdd(num){
//remove unintentional case
if(typeof num === "number"&&Number.isInteger(num))
{if(num%2===0){
console.log("even");
}
else{
console.log("odd");
}}
else{
console.log("not a integer number");
}
}
this way
if thee number is ever or odd
let num = 54
if (num%2 === 0){
console.log("num is even");
}else {
console.log("num is odd");
}
let number = 8
if(number % 2 == 0){
console.log("number is even")
} else{
console.log("number is odd")
}
Find out given number is even or off
Let num = 2
If (num%2 === 0) {
Console.log("given number is even");
}//% says 2/2 remainer is 0
else {
Console.log("given number is off");
}
Typo it's odd
let num = 1;
if(num%2==0)
{
console.log("num is even");
}
else{
console.log("the num is odd");
}
AND(&) operator
Semi colon (;) seems just a habit of java developer.
Is using brackets even if you have 1 statement in the block best practice?
yes, best practice use dry principle and use brackets and semicolon .
not a good practice but an unnecessary practice. you can put semi columns in python too :)
// why use of semicolon is important in javascript ?
// semicolon is used to separate the statements in javascript and avoid the errors in javascript that are not expected by the user .
since, javascript doesnot generate any error and if we use semicolon it prevent our code from error
let x = 10;
let result = x % 2;
if(result)
console.log("x is odd");
else
console.log("x is even");
let num1 = 6;
if (num1 % 2 === 0) {
console.log(num1 + " is even");
} else {
console.log(num1 + " is odd");
}
Thanks.
let num1 = 10;
let num2 = 11;
let num3 = 11;
if(num1 > num2 && num1 > num3){
console.log("num1 is greatest");
}
else if(num2 > num1 && num2 > num3){
console.log("num2 is greatest");
}
else{
console.log("num3 is greatest");
}
console.log("Code finished");
num3 is greatest?
since num2 is equal to num3 that's why else if condition fail and condition come to else part now use like that else if(num2>=num1&&num2>=num3)
console.log("num2 is greatest");
The if else is not clear sir, it's complex
x = 10;
y = 2;
if (x%y == 0){
console.log('even')
}
else{
console.log('odd')
}
@9:18
AND Operator
&&
its a logical operator check two conditon is true or false if both are true then true if atleast one of them is false then statement is flase
i like your series in general sir, but you should have told us how to take inputs before gioin into these stuff.... is FRUSTRATING not knowing how to get input and doing these operations , it makes programming boring, i already have experience in python
Perfect vscode them
What is the name of this theme?
//Assignment
let n = 30
if (n%2==0) {
console.log(n,'is an even number.');
} else {
console.log(n, 'is an odd number.');
}
Hello sir
let x=8
if(x%2==0)
console.log("even")
else
console.log("odd")
console.log("Happy coding")
/* 💻🖥📱*/
And opeartor
and operator
let a = number ("17");
if(a%2===0){
console.log("even");
}
else{
console.log("odd");
{
num = 19;
if (num%2==0) {
console.log("the number is even");
}
else{
console.log("the number is odd");
}
and operator(&&)
its a logical operator to add two condition and check both are true or not
🙏👍
9:23 &&
1st view and 1st like
Answer of the Assignment :
let num = 4
num%2==0?console.log("Even"):console.log("Odd")
Elif
AND
And
If(n%2)
console.log("odd");
else
console.log("even");
working fine but
you can use like that also
for better result
this conditon fail for string and float
use like this
if(typeof num === "number"&&Number.isInteger(num))
{if(num%2===0){
console.log("even");
}
else{
console.log("odd");
}}
else{
console.log("not a integer number");
}
Dude, improve your accent when talking in english
default
let num = 10;
if (num%2===0) {
console.log(String(num) +' '+'is an even number');
}
else{
console.log(String(num) +' '+'is an odd number');
}
let num1=5
if((num1)%2==0)
console.log('number is even');
else
console.log('number is odd');
let num = 69;
if (num & 1)
console.log ("The number is odd!");
else
console.log ("The number is even");