Select a Random Item from an Array using JavaScript

The snippet below selects a random item from an array and show it in an alert box using Javascript. <script> var arr = [ "ASP.NET", "C", "C++", "C#", "Java", "JavaScript", "MVC CORE", "VB.NET" ]; var random = arr[Math.floor(Math.random()*arr.length)]; alert(random) </script> Happy Coding! Related Snippets

Find Factorial of a Number using Recursion in C++

First of all, we need to understand the concept of recursion and factorial to write this program. What is Recursion? It is an essential concept in computer science. In computer science, recursion is a process in which a function calls itself directly or indirectly. Recursion function must have the following two properties: What is Factorial?... » read more

Get local IP Address using C

Here is the source code of the program in C to get the local IP address. This program is successfully compiled, and the output is also given below. C program to get local IP Address #include<stdlib.h> #include<hostname> #include <stdio.h> struct hostent *he_bool; struct in_addr a; int main (int argc) { char *hostname = malloc (MAXHOSTNAMELEN);... » read more

Check if a given String is Palindrome using C

A string is said to be palindrome if it remains unchanged after reversing it.  For Example 4646, aeoaeo, mom, dad, and nana are some examples of palindrome strings. Below is the source code of the program in C to check if a given string is Palindrome. This program is successfully compiled, and the output is... » read more

Convert Roman Number to Decimal Number Using C

Below is a C program which takes a roman number form the user and convert it into a decimal number. We need to understand what the roman number is. What are Roman Numbers? The Roman numbers are represented by the combination of letter from Latin alphabets. It is a numeric system that was devised in... » read more

How to Check if a Matrix is Invertible using C++

To write this program, we need to understand the concept of invertible. A matrix (A)n ×n is said to be invertible if and only if there exists another matrix (B)n ×n such that AB=BA=ln. A matrix is invertible if and only if its determinant is not zero. A matrix is singular or not invertible if... » read more

Convert Hexadecimal to Binary using C

Below is a c program which takes a hexadecimal number as an input and converts it into a binary number. Convert Hexadecimal to Binary in C Here is the source code of the program in C to Convert Hexadecimal number to Binary number. This program is successfully compiled, and the output is also given below.... » read more

Find Factorial of a Number using Iteration in C++

The following is a program to find a factorial of a number using iteration in C++. To write this program, first of all, we need to understand the concept of factorial. What is Factorial? Factorial is represented by an exclamation mark (!). Factorial of n number is the product of all integers greater than or... » read more

PHP Object-Oriented Programming

In this lesson, you will learn about the basic features of object-oriented programming with PHP. The OOP is not a new way to write code, but it is entirely a different approach to writing code. With procedural language, the focus is on the actions whereas in OOP the focus in on the nouns. PHP and... » read more

Simulate a ‘N’ Roller Dice using C++

A dice roller grants you to roll a constructive dice. It is used to generate a sequence of random number mainly use in gambling games like Backgammon, sic bo or Yahtzee. A computational device uses to create a series of random symbols or numbers with lack of any pattern. How to simulate a Roller Dice... » read more

Find the First Capital Letter in a String using C

In this article, we are going to write a  program to find the first capital letter in a string using recursion in C programming language. First of all, we included ctype.h header file in our program. ctype.h header file contains many functions, such as the function, which will be used in our program. If the... » read more

PHP and JSON

In this lesson, you will learn how to use JSON with PHP for web development. What is JSON? JSON is a short form of JavaScript Object Notation. It is not a programming language itself; it is merely a data format which is used to exchange data between a server and a web browser. Now you... » read more

PHP Error handling

In this lesson, you will learn more about PHP’s way to handle errors and catch exceptions. Handling errors and exceptions in a progressive manner isn’t difficult and somewhat similar to how other C++ or Perl handle errors or catch exceptions. Error handling lets you catch errors caused by your code and taking appropriate action according... » read more

An encoding of a message using matrix multiplication in C++

Encoding is performed between a given matrix and key matrix using matrix multiplication. We included header file conio.h to use getch() function which is used to stop the output screen from blinking. Message encoding using matrix multiplication in C++ Below is a C++ program that an encoding of a message using matrix Multiplication. This program... » read more