Question

In: Computer Science

Write Javascript code for the function malwareFrequencies() that shows the malware analyst a prompt. The analyst...

Write Javascript code for the function malwareFrequencies() that shows the malware analyst a prompt. The analyst enters a list of malware names (separated by spaces) for each malware incident they have heard about in the last month.  Note that the same malware can be involved in multiple incidents. Your function should print those malware names and their frequencies to the screen. Sample output is shown below.

Zeus 1

Emotet 3

WannaCry 2

Emotet 3

Emotet 3

WannaCry 2

Solutions

Expert Solution

Since there were no particular instructions, i wrote the simplest code.

you want to modify the method for prompt according to your JS environment.

I've split the code into two functions so that it gets easier to understand

please drop a comment if there's an issue.

//-------------INPUT/OUTPUT-----------------------

//---------------------------------------------------------

//this function counts the occurence of "malware" in "list"

function count(list, malware) {

    //intitialization

    let freq = 0;

    //loops over the entire list

    for (let i = 0; i < list.length; i++) {

        //checks if the curret elemnt is same as "malware"

        if (list[i] == malware) {

            //incremnts

            freq++;

        }

    }

    return freq;

}

//this is the required function

function malwareFrequencies() {

    //PROMPT

    let input = prompt("Enter the malwate list: ");

    //splits the entered string into a list

    let list = input.split(" ")

    //loops over the list

    for (let i = 0; i < list.length; i++) {

        //prints the current elment along with their frequency

        console.log(list[i], count(list, list[i]))

    }

}

malwareFrequencies();


Related Solutions

Write the below code to use HTML and JavaScript. 1. a) Write a JavaScript program to...
Write the below code to use HTML and JavaScript. 1. a) Write a JavaScript program to display the current day and time. b) Write a JavaScript program to print the contents of the current window.   c) Write a JavaScript program where the program takes a random integer between 1 to 10 d) Write a JavaScript program to calculate multiplication and division of two numbers (input from the user). e)Write a JavaScript program to create a new string from a given...
Palindrome Javascript I am trying to write this javascript function to check if a number is...
Palindrome Javascript I am trying to write this javascript function to check if a number is Palindrome.. Palindrome means - a word, phrase, or sequence that reads the same backward as forward, e.g., madam or nurses run. This is the code i have, but it doesnt work. Code: let convertButton = document.getElementsByClassName("btn")[0]; let userInput = document.getElementById("number").value; let results = document.getElementById("result").value; convertButton.addEventListener("click", function (event) { event.preventDefault(); console.log(userInput); if (validatePalidrome(userInput)) document.getElementById("result").innerHTML = "true"; else document.getElementById("result").innerHTML = "false"; }); function validatePalidrome(numbers) { let...
Palindrome Javascript - NUMBERS I am trying to write this javascript function to check if a...
Palindrome Javascript - NUMBERS I am trying to write this javascript function to check if a number is Palindrome.. Palindrome means - a word, phrase, or sequence that reads the same backward as forward, e.g., 12321 This is the code i have, but it doesnt work. PLEASE MAKE SURE IT WORK BEFORE POST ANSWER, I GOT @ CODE THAT DID WORK BEFORE HTML JavaScript Palindrome Exercise rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css" /> Palindrome Enter a positive number: Is this a palindrome? No...
Write a response to the prompt and provide sources. You are the senior analyst in the...
Write a response to the prompt and provide sources. You are the senior analyst in the FBI’s cybercrime division. The executive director for criminal, cyber, response, and services branch has asked you to provide an assessment of where the FBI needs to be by 2020 in regard to combating cybercrime. The ED is looking for how best to engage the private sector, as well as other parts of government in order to help achieve this objective.
JAVASCRIPT HTML I'm looking to make a function that will take a postal code in a...
JAVASCRIPT HTML I'm looking to make a function that will take a postal code in a text box. The function jobs is to basically make sure the first letter of the postal code starts with these letters. ('A') ('N") ('W') ('F'). If the first letter of the postal code does not match up then an error to the user is sent.
(Full Program)Write code that shows how deadlocks work. Then write code that shows a fix using...
(Full Program)Write code that shows how deadlocks work. Then write code that shows a fix using semaphores. (Full program)Write code showing the elevator algorithm. c++ Language
Write a function in JAVASCRIPT that accepts an array as argument. The function should loop through...
Write a function in JAVASCRIPT that accepts an array as argument. The function should loop through the array elements and accumulate the sum of ASCII value of each character in element and return the total. For example: function([‘A’, ‘bc’, 12]); // returns 361 which is the sum of 65 + 98 + 99 + 49 + 50 Use of any built in string functions or built in array functions is not allowed, Any help would be much appreciated
Write a javascript code to check if the JSON body follows the schema. schema is {...
Write a javascript code to check if the JSON body follows the schema. schema is {     "name":"john doe",     "mood":"happy"     "major":"cs",     "date":"2024" } json body is {     "name":"john doe", "height":"170cm"     "major":"cs",     "date":"2024" } the result should be false
JavaScript Write a function called "first" that takes in two arguments - the first is an...
JavaScript Write a function called "first" that takes in two arguments - the first is an argument called arr that is an array of numbers, the second is an optional number argument called num(hint: you'll need a default value - look back at the slides). If "num" was not passed in (since it's optional), the "first" function will return an array containing the first item of the array. If a value for "num" was given, the "first" function will return...
Write a javascript code to replace the JSON body with another JSON body. JSON body1 {...
Write a javascript code to replace the JSON body with another JSON body. JSON body1 {     "name":"john doe",     "mood":"happy"     "major":"cs",     "date":"2024" } json body2 is { "mood":"sad"     "major":"accounting",     "date":"2023" } the result should be { "name":"john doe", "mood":"sad"     "major":"accounting",     "date":"2023" }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT