diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/README.md b/README.md index 822b364..51ce099 100644 --- a/README.md +++ b/README.md @@ -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 “hr@ignitershub.com”. + +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. \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..1dd72ee --- /dev/null +++ b/package-lock.json @@ -0,0 +1,24 @@ +{ + "name": "delete-assignment", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "delete-assignment", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "nodemailer": "^6.9.13" + } + }, + "node_modules/nodemailer": { + "version": "6.9.13", + "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.13.tgz", + "integrity": "sha512-7o38Yogx6krdoBf3jCAqnIN4oSQFx+fMa0I7dK1D+me9kBxx12D+/33wSb+fhOCtIxvYJ+4x4IMEhmhCKfAiOA==", + "engines": { + "node": ">=6.0.0" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..872c89d --- /dev/null +++ b/package.json @@ -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" + } +} diff --git a/src/attachment.png b/src/attachment.png new file mode 100644 index 0000000..5249034 Binary files /dev/null and b/src/attachment.png differ diff --git a/src/challenge1.js b/src/challenge1.js new file mode 100644 index 0000000..e28652e --- /dev/null +++ b/src/challenge1.js @@ -0,0 +1,35 @@ +const nodemailer = require("nodemailer"); + +const transport = nodemailer.createTransport({ + host: "smtp-relay.brevo.com", + port: 587, + secure: false, + auth: { + user: "76c643001@smtp-brevo.com", + pass: "n4NQS6Td5mOwFWr7", + }, +}); + +const mailOptions = { + from: "shatakshishri@gmail.com", + to: "hr@ignitershub.com", + 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() diff --git a/src/challenge2/index.html b/src/challenge2/index.html new file mode 100644 index 0000000..5c92a67 --- /dev/null +++ b/src/challenge2/index.html @@ -0,0 +1,11 @@ + + + + + + Document + + + + + \ No newline at end of file diff --git a/src/challenge2/script.js b/src/challenge2/script.js new file mode 100644 index 0000000..90e6f11 --- /dev/null +++ b/src/challenge2/script.js @@ -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); diff --git a/src/challenge3/index.html b/src/challenge3/index.html new file mode 100644 index 0000000..5c92a67 --- /dev/null +++ b/src/challenge3/index.html @@ -0,0 +1,11 @@ + + + + + + Document + + + + + \ No newline at end of file diff --git a/src/challenge3/script.js b/src/challenge3/script.js new file mode 100644 index 0000000..d3af5df --- /dev/null +++ b/src/challenge3/script.js @@ -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); diff --git a/src/challenge4/index.html b/src/challenge4/index.html new file mode 100644 index 0000000..5c92a67 --- /dev/null +++ b/src/challenge4/index.html @@ -0,0 +1,11 @@ + + + + + + Document + + + + + \ No newline at end of file diff --git a/src/challenge4/script.js b/src/challenge4/script.js new file mode 100644 index 0000000..7f80459 --- /dev/null +++ b/src/challenge4/script.js @@ -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) \ No newline at end of file