I need to solve this school exercise but I don't know how. Here's the text:
I need to make a program that takes information from the user via prompt() dialog. The information that user needs to enter is his name and sex (eg. Marc, m). Based on that information, the program needs to write in alert() dialog the adjectives from the (already given) list that start with the same letter as the letters from the name.
For example: user's name is Marc, and his sex is male. Program needs to use adjectives from the male list (there are two lists with adjectives, for both male and female), and to write them like this in alert dialog:
Mad
Accurate
Reasoning
Calculative
If you read their first letters vertically, they say MARC.
I have adjectives for all the letters in alphabet, for both male and female. Keep in mind that variable names and adjectives are on my native language (Serbian), but it shouldn't be the problem, you will get the point and I will explain the code in the comments.
var pridevi = {
m: ["atraktivan", "blesav", "ciničan", "čudan", "ćopav", "duhovit", "džangrizav", "đavolast", "elokventan", "fantastičan", "grozan", "halapljiv", "imućan", "jak", "katastrofalan", "lep", "ljubazan", "mudar", "naivan", "njanjav", "otporan", "posesivan", "razigran", "smešan", "šaljiv", "tolerantan", "uobražen", "veseo", "zabrinut", "žut"],
z: ["atraktivna", "blesava", "cinična", "čudna", "ćopava", "duhovita", "džangrizava", "đavolasta", "elokventna", "fantastična", "grozna", "halapljiva", "imućna", "jaka", "katastrofalna", "lepa", "ljubazna", "mudra", "naivna", "njanjava", "otporna", "posesivna", "razigrana", "smešna", "šaljiva", "tolerantna", "uobražena", "vesela", "zabrinuta", "žuta"],
} // I stored adjectives in object where property m: stands for male and property f: stands for female adjectives
var unos = prompt("Upišite ime i pol. Npr. Mirko, m"); // prompt format
var ime = unos.toLowerCase().split(", ").shift(); // in this variable I stored name
var pol = unos.toLowerCase().split(", ").pop(); // in this variable I stored sex
// console.log(ime + " " + pol) > mirko m
if (unos === null) {
alert("Korisnik je odustao."); // if user clicks cancel, this message shows in alert dialog
}
else if (unos === undefined && ime < 0 && pol < 0) {
alert("Nisu uneseni ispravni podaci."); // if user doesn't write the data in correct form, this message shows in alert dialog
}
else {
var odgovor = pridevi[pol].find(opis => ime[0] === opis[0]); // here's the main thing that doesn't work as it should. it only shows the adjective of the first letter of the name, but not all of them
alert(odgovor);
}