Posts

JavaScript syntax

  JavaScript syntax // How to create variables: var  x; let  y; // How to use variables: x =  5 ; y =  6 ; let  z = x + y; The two most important syntax rules for fixed values are: 1.  Numbers  are written with or without decimals: 10.50 1001 2. Strings are text, written within double or single quotes: example: "John Doe" 'John Doe' JavaScript Variables In a programming language,  variables  are used to  store  data values. JavaScript uses the keywords  var ,  let  and  const  to  declare  variables. An  equal sign  is used to  assign values  to variables. In this example, x is defined as a variable. Then, x is assigned (given) the value 6: example : let  x; x =  6 ; JavaScript Operators JavaScript uses arithmetic operators ( + - * / ) to compute values: example : JavaScript uses an assignment operator ( = ) to assign values to variables: example : let  x, y;...

JavaScript Statements

JavaScript Statements JavaScript statements are composed of: Values, Operators, Expressions, Keywords, and Comments. This statement tells the browser to write "Hello Dolly." inside an HTML element with id="demo":   let  x, y, z;     // Statement 1 x =  5 ;           // Statement 2 y =  6 ;           // Statement 3 z = x + y;       // Statement 4 Semicolons separate JavaScript statements. Add a semicolon at the end of each executable statement: let  a, b, c;   // Declare 3 variables a =  5 ;         // Assign the value 5 to a b =  6 ;         // Assign the value 6 to b c = a + b;     // Assign the sum of a and b to c

JavaScript

The JavaScript language Here we learn JavaScript, starting from scratch and go on to advanced concepts like OOP. We concentrate on the language itself here, with the minimum of environment-specific notes

Python Program to Find the Factorial of a Number

Python Program to Find the Factorial of a Number  # Python program to find the factorial of a number provided by the user. # change the value for a different result num = 7 # uncomment to take input from the user #num = int(input("Enter a number: ")) factorial = 1 # check if the number is negative, positive or zero if num < 0:    print("Sorry, factorial does not exist for negative numbers") elif num == 0:    print("The factorial of 0 is 1") else:    for i in range(1,num + 1):        factorial = factorial*i    print("The factorial of",num,"is",factorial)

Python Program to Print all Prime Numbers in an Interval

Python Program to Print all Prime Numbers in an Interval  # Python program to display all the prime numbers within an interval # change the values of lower and upper for a different result lower = 800 upper = 1000 # uncomment the following lines to take input from the user #lower = int(input("Enter lower range: ")) #upper = int(input("Enter upper range: ")) print("Prime numbers between",lower,"and",upper,"are:") for num in range(lower,upper + 1):    # prime numbers are greater than 1    if num > 1:        for i in range(2,num):            if (num % i) == 0:                break        else:            print(num) output: Prime numbers between 800 and 1000 are: 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 ...

Python Program to Check Prime Number

Python Program to Check Prime Number # Python program to check if the input number is prime or not num = 407 # take input from the user # num = int(input("Enter a number: ")) # prime numbers are greater than 1 if num > 1:    # check for factors    for i in range(2,num):        if (num % i) == 0:            print(num,"is not a prime number")            print(i,"times",num//i,"is",num)            break    else:        print(num,"is a prime number")        # if input number is less than # or equal to 1, it is not prime else:    print(num,"is not a prime number") output: 407 is not a prime number 11 times 37 is 407  In this program, variable num is checked if it's prime ...

Add Two Numbers Provided by The User

Add Two Numbers Provided by The User # Store input numbers num1 = input ( 'Enter first number: ' ) num2 = input ( 'Enter second number: ' ) # Add two numbers sum = float ( num1 ) + float ( num2 ) # Display the sum print ( 'The sum of {0} and {1} is {2}' . format ( num1 , num2 , sum ))      output:   Enter first number: 1.5 Enter second number: 6.3 The sum of 1.5 and 6.3 is 7.8