OneCompiler

DS19

110

Q. 1) Write a Java Script Program to validate user name and password on onSubmit event.
[Marks 15]

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>JavaScript Validation</title> <script> function validateForm() { var username = document.getElementById("username").value; var password = document.getElementById("password").value;
// Check if username and password are empty
if (username == "" || password == "") {
    alert("Username and password are required!");
    return false;
}

// Check if username contains only alphanumeric characters
var alphanumeric = /^[a-zA-Z0-9]+$/;
if (!username.match(alphanumeric)) {
    alert("Username must contain only alphanumeric characters!");
    return false;
}

// Check if password length is between 6 and 20 characters
if (password.length < 6 || password.length > 20) {
    alert("Password must be between 6 and 20 characters long!");
    return false;
}

return true;

}
</script>

</head> <body> <h2>User Login</h2> <form onsubmit="return validateForm()"> Username: <input type="text" id="username"><br> Password: <input type="password" id="password"><br> <input type="submit" value="Login"> </form> </body> </html>

Q. 2)Download the movie_review.csv dataset from Kaggle by using the following link
to perform
sentiment analysis on above dataset and create a wordcloud
import pandas as pd
from wordcloud import WordCloud
import matplotlib.pyplot as plt

Read the dataset

df = pd.read_csv("movie_review.csv")

Perform sentiment analysis (example: assume positive if rating > 5)

df['Sentiment'] = df['Rating'].apply(lambda x: 'positive' if x > 5 else 'negative')

Concatenate all reviews

all_reviews = ' '.join(df['Review'])

Generate wordcloud

wordcloud = WordCloud(width=800, height=400, background_color='white').generate(all_reviews)

Plot wordcloud

plt.figure(figsize=(10, 5))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
plt.show()