Day: March 22, 2021

JS Example for Beginners: Javascript Program to Check if a Number is Odd or Even

(JavaScript programming Example for Beginners) Javascript Program to Check if a Number is Odd or Even In this example, you will learn to write a JavaScript program to check if the number is odd or even. Even numbers are those numbers that are exactly divisible by 2. The remainder operator % gives the remainder when used with a number. …

JS Example for Beginners: Javascript Program to Check if a number is Positive, Negative, or Zero

(JavaScript programming Example for Beginners) Javascript Program to Check if a number is Positive, Negative, or Zero In this example, you will learn to check whether the number entered by the user is positive, negative or zero.   You will be using the if…else if…else statement to write the program. Example 1: Check Number Type with if…else …

JS Example for Beginners: Javascript Program to Generate a Random Number

(JavaScript programming Example for Beginners) Javascript Program to Generate a Random Number In this example, you will learn to generate a random number in JavaScript.   In JavaScript, you can generate a random number with the Math.random() function. Math.random() returns a random floating-point number ranging from 0 to less than 1 (inclusive of 0 and exclusive of 1) Example 1: Generate a Random Number // …

JS Example for Beginners: Javascript Program to Convert Celsius to Fahrenheit

(JavaScript programming Example for Beginners) Javascript Program to Convert Celsius to Fahrenheit In this example, you will learn to convert Celsius value to Fahrenheit in JavaScript.   You can convert the celsius value to fahrenheit by using the formula: fahrenheit = celsius * 1.8 + 32 Example: Celsius to Fahrenheit // program to convert celsius …

JS Example for Beginners: JavaScript Program to Convert Kilometers to Miles

(JavaScript programming Example for Beginners) JavaScript Program to Convert Kilometers to Miles In this example, you will learn how to convert the kilometers value to miles in JavaScript. We know that 1 kilometer is equal to 0.621371 miles. So to convert kilometers to miles, you can use the formula: miles = kilometers * factor Example 1: Kilometers to Miles …

JS Example for Beginners: JavaScript Program to Swap Two Variables

(JavaScript programming Example for Beginners)   JavaScript Program to Swap Two Variables In this example, you will learn to write a program to swap two variables in JavaScript using various methods.   Example 1: Using a Temporary Variable //JavaScript program to swap two variables //take input from the users let a = prompt(‘Enter the first …

JS Example for Beginners: JavaScript Program to Find the Square Root

(JavaScript programming Example for Beginners) JavaScript Program to Find the Square Root In this example, you’ll learn to write a program to find the square root of a number in JavaScript. To find the square root of a number in JavaScript, you can use the built-in Math.sqrt() method. Its syntax is: Math.sqrt(number); Here, the Math.sqrt() method takes a number …

JS Example for Beginners: JavaScript Program To Print Hello World

(JavaScript programming Example for Beginners) JavaScript Program To Print Hello World In this example, you will learn to print ‘Hello World’ in JavaScript in three different ways. A “Hello, World!” is a simple program that prints Hello, World! on the screen. Since it’s a very simple program, this program is often used to introduce a new programming …

C Example for Beginners: C Program to Display its own Source Code as Output

(C programming Example for Beginners) C Program to Display its own Source Code as Output In this example, you’ll learn to display source of the program using __FILE__ macro. Though this problem seems complex, the concept behind this program is straightforward; display the content from the same file you are writing the source code. In …