Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assignment (by shatakshi shrivastava) #11

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,55 @@
# interns-assignments
completed by: shatakshi shrivastava
Project Title
Challenge1:
Write a program to programmatically trigger an email.

The program must be able to send an email to “[email protected]”.

The Subject of the email Should mention “Challenge 3 Completed”.

The body of the email should contain:

Your name, semester, branch, and roll number
An image attachment. (Only images of type PNG, JPG, JPEG are allowed.)
During the development, please use your personal email id to test the program.

Deployment
To deploy this project
run the following commands in the ternimal:
npm i
cd src
node challenge1.js

challenge 2 – Palindrome Checker
Write a program that checks whether a given string is a palindrome or not. A
palindrome is a word, phrase, or sequence of characters that reads the same
backwards as forward.

Language:- Any (i.e. Java, C, C++, JavaScript, Python, etc.). However, preferred is Java.

Your program should prompt the user to enter a string, and then it should determine and
display whether the input string is a palindrome or not.

Deployment
To deploy this project simply run it in browser.

challenge 3 – Binary Search
Write a program that implements the binary search algorithm to search for a
specific element in a sorted array. The program should allow the user to input a
target element and then search for that element in the sorted array. It should
return the index of the element if found or indicate that the element is not in
the array.

Language:- Any (i.e. Java, C, C++, JavaScript, Python, etc.). However, preferred is Java.
Deployment
To deploy this project simply run it in browser.

Challenge 4 – String Manipulation
Write a program that takes a sentence as input and performs the following
operations:
1.Count the number of words in the sentence.
2.Reverse the order of words in the sentence.
3.Replace all spaces with hyphens ('-').

Language:- Any (i.e. Java, C, C++, JavaScript, Python, etc.). However, preferred is Java.
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "assignment",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"nodemailer": "^6.9.13"
}
}
Binary file added src/attachment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions src/challenge1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const nodemailer = require("nodemailer");

const transport = nodemailer.createTransport({
host: "smtp-relay.brevo.com",
port: 587,
secure: false,
auth: {
user: "[email protected]",
pass: "n4NQS6Td5mOwFWr7",
},
});

const mailOptions = {
from: "[email protected]",
to: "[email protected]",
subject: "Challenge 3 Completed",
text: `Name: Shatakshi Shrivastava
Semester: 8th
Branch: Electronics and Communications
Roll Number: 12015119
`,
attachments: [
{
filename: "attachment.png",
path: "./attachment.png",
},
],
};

async function sendMail(){
const result = await transport.sendMail(mailOptions)
console.log(result);
}

sendMail()
11 changes: 11 additions & 0 deletions src/challenge2/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
20 changes: 20 additions & 0 deletions src/challenge2/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function isPalindrome(str) {
let revStr = "";
for (let i = str.length - 1; i >= 0; i--) {
revStr += str[i];
}
if (str === revStr) return true;
return false;
}

let userInput = prompt("Enter a string to check if it is a palindrome:");

let ans = "";

if (isPalindrome(userInput)) {
ans = `The string '${userInput}' is a palindrome`;
} else {
ans = "The string is not a palindrome.";
}

alert(ans);
11 changes: 11 additions & 0 deletions src/challenge3/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
35 changes: 35 additions & 0 deletions src/challenge3/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
function binarySearch(arr, target) {
let left = 0;
let right = arr.length - 1;

while (left <= right) {
let mid = Math.floor((left + right) / 2);

if (arr[mid] === target) {
return mid; // Target element found
} else if (arr[mid] < target) {
left = mid + 1; // Search in the right half
} else {
right = mid - 1; // Search in the left half
}
}
return -1; // Target element not found
}

let sortedArray = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19];

let userInput = prompt("Enter the target element to search for:");

let targetElement = parseInt(userInput, 10);

let result = binarySearch(sortedArray, targetElement);

let ans = ""

if (result !== -1) {
ans = `Element ${targetElement} is found at index ${result}.`;
} else {
ans = "Element not found in the array."
}

alert(ans);
11 changes: 11 additions & 0 deletions src/challenge4/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
27 changes: 27 additions & 0 deletions src/challenge4/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function countWords(sentence) {
let words = sentence.trim().split(/\s+/);
return words.length;
}

function reverseWords(sentence) {
let words = sentence.trim().split(/\s+/);
return words.reverse().join(' ');
}

function replaceSpacesWithHyphens(sentence) {
return sentence.replace(/\s+/g, '-');
}

let userInput = prompt("Enter a sentence:");

let wordCount = countWords(userInput);
let reversedSentence = reverseWords(userInput);
let hyphenatedSentence = replaceSpacesWithHyphens(userInput);

let ans = `
Number of words: ${wordCount}
Reversed sentence: ${reversedSentence}
Modified sentence: ${hyphenatedSentence}
`

alert(ans)