Professional Documents
Culture Documents
Codechum 17
Codechum 17
function square(num) {
var result = num * num;
console.log(result);
}
// Example usage:
var userInput = parseInt(prompt("Enter a number: "));
if (isNaN(userInput)) {
console.log("Invalid input. Please enter a valid number.");
} else {
square(userInput);
}
//Multiplying 2 Numbers
// Example usage:
var input1 = parseFloat(prompt("Enter first number: "));
var input2 = parseFloat(prompt("Enter second number: "));
if (isNaN(input1) || isNaN(input2)) {
console.log("Invalid input. Please enter valid numbers.");
} else {
multiply(input1, input2);
}
function calculateAverage() {
var total = 0;
var count = arguments.length;
// Example usage:
var input1 = parseFloat(prompt("Enter the first number: "));
var input2 = parseFloat(prompt("Enter the second number: "));
var input3 = parseFloat(prompt("Enter the third number: "));
function checkNumber(number) {
if (number > 0) {
console.log("Positive");
} else if (number < 0) {
console.log("Negative");
} else {
console.log("Zero");
}
}
// Example usage:
var userInput = parseFloat(prompt("Enter a number: "));
if (isNaN(userInput)) {
console.log("Invalid input. Please enter a valid number.");
} else {
checkNumber(userInput);
}
//Printing Patterns
function printPattern(rows) {
for (var i = 1; i <= rows; i++) {
var line = '';
for (var j = 1; j <= i; j++) {
line += '*';
}
console.log(line);
}
}
// Example usage:
var userInputRows = parseInt(prompt("Enter the number of rows: "));
//BMI Calculation
// Example usage:
var userInputWeight = parseFloat(prompt("Enter your weight in kilograms: "));
var userInputHeight = parseFloat(prompt("Enter your height in meters: "));