Skip to content

Latest commit

 

History

History
16 lines (12 loc) · 513 Bytes

4.2HelloWorld.md

File metadata and controls

16 lines (12 loc) · 513 Bytes

Exercises

  • Modify the greet function in wasm-game-of-life/src/lib.rs to take a name: &str parameter that customizes the alerted message, and pass your name to the greet function from inside wasm-game-of-life/wasm-app/index.js. Rebuild the .wasm binary with wasm-pack build, then refresh in your web browser and you should see a customized greeting!

Answer:

#[wasm_bindgen]
pub fn greet(name: &str) {
  alert(&format!("Hello, {}!", name));
}
wasm.greet("Your name");