FS JS PP01 Programming Constructs Practice Problems
FS JS PP01 Programming Constructs Practice Problems
Programming
Constructs
NodeJs – CLI (Command Line Interface) Installation
• Step 1: Check Homebrew Package Manager is installed using
• brew –version - in the Terminal of Linux/Mac or in the Command Line of Windows
Step 5: Browser will open in Debug mode. Please refer next slide.
Step 6: On the debug prompt use next to proceed to next line
Step 7: cont to complete the Program execution and
Step 8: use .exit or ctrlC twice to exit node command prompt.
Click Here
Node.js
Debugger Click On Inspect
Node.js Debugger Window
add.js debug console
F8 – Resume Script Execution
F9 – Execute the Current Line
F10 – Step Over
F11 – Step Into
Shift F11 – Step Out
1. Write a program that reads 5 Random 3 Digit values and then outputs the minimum
and the maximum value
2. Write a program that takes day and month from the command line and prints true if
day of month is between March 20 and June 20, false otherwise.
3. Write a program that takes a year as input and outputs the Year is a Leap Year or not
a Leap Year. A Leap Year checks for 4 Digit Number, Divisible by 4 and not 100 unless
divisible by 400.
4. Write a program to simulate a coin flip and print out "Heads" or "Tails" accordingly.
Selection Practice Problems with if else if and else
1. Read a single digit number and write the number in word using Case
2. Read a Number and Display the week day (Sunday, Monday,…)
3. Read a Number 1, 10, 100, 1000, etc and display unit, ten, hundred,…
4. Write a program that takes User Inputs and does Unit Conversion of
different Length units
1. Feet to Inch 3. Inch to Feet
2. Feet to Meter 4. Meter to Feet
for Loop Statement
Repetition Practice Problems with for loop
1. Write a program that takes a command-line argument n and prints a table of the
powers of 2 that are less than or equal to 2^n.
2. Write a program that takes a command-line argument n and prints the nth harmonic
number. Harmonic Number is of the form
3. Write a program that takes a input and determines if the number is a prime.
4. Extend the program to take a range of number as input and output the Prime
Numbers in that range.
5. Write a program that computes a factorial of a number taken as input.
5 Factorial – 5! = 1 * 2 * 3 * 4 * 5
6. Write a program to compute Factors of a number N using prime factorization method.
Logic -> Traverse till i*i <= N instead of i <= N for efficiency.
O/P -> Print the prime factors of number N.
while Loop Statement
Repetition Practice Problems with while loop
1. Write a program that takes a command-line argument n and prints a
table of the powers of 2 that are less than or equal to 2^n till 256 is
reached..
2. Find the Magic Number
a. Ask the user to think of a number n between 1 to 100
b. Then check with the user if the number is less then n/2 or greater
c. Repeat till the Magic Number is reached..
3. Extend the Flip Coin problem till either Heads or Tails wins 11 times.
4. Write a Program where a gambler starts with Rs 100 and places Re 1 bet
until he/she goes broke i.e. no more money to gamble or reaches the
goal of Rs 200. Keeps track of number of times won and number of bets
made.
• Functions are a great way to reuse
code.
• Think of a function as a small script
within a script. It's a small chunk of
code which you may call multiple
times within your script. They are
4. Functions particularly useful if you have certain
tasks which need to be performed
several times.
Demonstrate
Functions and
Functional
Expressions
Functions Practice Problems
1. Help user find degF or degC based on their Conversion Selection. Use
Case Statement and ensure that the inputs are within the Freezing Point (
0 °C / 32 °F ) and the Boiling Point of Water ( 100 °C / 212 °F )
a. degF = (degC * 9/5) + 32
b. degC = (degF – 32) * 5/9
2. Write a function to check if the two numbers are Palindromes
3. Take a number from user and check if the number is a Prime then show
that its palindrome is also prime
a. Write function check if number is Prime
b. Write function to get the Palindrome.
c. Check if the Palindrome number is also prime
Thank
You