wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
list.forEach(function(item) {{ console.log(item); }}) | list.forEach((item) => {{ console.log(item); }}) | Arrow functions are cleaner. | JavaScript |
object Item {{ def main(args: Array[String]) = println("value") }} | object Item {{ def main(args: Array[String]): Unit = println("value") }} | Add return type Unit. | Scala |
List(70,60,1) | List(70,60,1) | Correct. | Scala |
$arr[57] | if ($arr.Count -gt 57) {{ $arr[57] }} | Check bounds. | PowerShell |
echo data hello | echo 'data hello' | Quote to prevent splitting. | Shell |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
let temp: i32 = "output"; | let temp: &str = "output"; | Type mismatch. | Rust |
if ($index = 39) {{}} | if ($index -eq 39) {{}} | Use -eq. | PowerShell |
<div><p>message</div></p> | <div><p>message</p></div> | Nest properly. | HTML |
int &ref; | int x; int &ref = x; | Reference must be initialized. | C++ |
let mut bar=85; let r1=&mut bar; let ref2=&mut bar; | let mut bar=85; {{ let r1=&mut bar; }} let ref2=&mut bar; | Only one mutable borrow. | Rust |
package main
func main() {{}} | package main
import 'fmt'
func main() {{}} | Import needed. | Go |
'output' + 1 | 'output' + 1.to_s | Convert int. | Ruby |
h1 {{ font-size:17px color:blue; }} | h1 {{ font-size:17px; color:blue; }} | Add semicolon. | CSS |
let v=vec![93,10,89]; let first=&v[0]; v.push(3); | let mut v=vec![93,10,89]; let first=v[0]; v.push(3); | Copy instead of reference. | Rust |
if (x = 90) | if (x == 90) | Use ==. | Scala |
jwt.sign({{id:58}}, 'secret'); | jwt.sign({{id:58}}, 'secret', {{expiresIn:'30m'}}); | Add expiration. | Node.js |
console.log('data' | console.log('data') | Close parenthesis. | JavaScript |
let bar = 25; let bar = 78; | let bar = 25; bar = 78; | Duplicate declaration. | JavaScript |
while read line; do echo $line; done < log.txt | while read line; do echo $line; done < log.txt | Correct. | Shell |
<ul><li>hello<li>hello</ul> | <ul><li>hello</li><li>hello</li></ul> | Close li. | HTML |
SELECT age role FROM orders; | SELECT age, role FROM orders; | Add comma. | SQL |
x <- 5; if (x > 3) print('large') | x <- 5; if (x > 3) print('large') | Correct. | R |
let str1 = String::from("info"); let s2 = str1; println!("{{}}", str1); | let str1 = String::from("info"); let s2 = str1.clone(); println!("{{}}", str1); | Clone to avoid move. | Rust |
<center>result</center> | <div style='text-align:center;'>result</div> | Use CSS. | HTML |
local temp = 78 | local temp = 78 | Correct. | Lua |
cin >> item; | int item;
cin >> item; | Declare variable. | C++ |
b > 84 & b < 24 | b > 84 and b < 24 | Use 'and' not '&'. | Python |
if a > 56
print('result') | if a > 56:
print('result') | Colon missing after if. | Python |
if (c) console.log('yes') else console.log('no') | if (c) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
val count = 12; count = 45 | var count = 12; count = 45 | Use var for reassignment. | Scala |
for (b in items) | for (b of items) | for...in iterates keys. | JavaScript |
if count = 36 | if count == 36 | Use ==. | MATLAB |
var x = 5; x = true | var x = 5; x = 10 | Type mismatch. | Kotlin |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
<div color=green> | <div style='color:green;'> | Use style attribute. | CSS |
int* p = nullptr; *p=5; | int* p = new int; *p=5; | Allocate memory. | C++ |
for (int i=0; i<59; i++) {{}} | for (int i=0; i<59; i++) {{}} | Correct. | Java |
int list[81]; list[81]=5; | int list[81]; if(81<81){{}} else list[81]=5; | Bounds check. | C++ |
result = hello | result = 'hello' | Quote strings. | Python |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
if (index = 49) | if (index == 49) | Use ==. | R |
{{'name':14, 'value' 74}} | {{'name':14, 'value':74}} | Colon missing. | Python |
<note><desc>info</desc><age>1</age></note | <note><desc>info</desc><age>1</age></note> | Add closing >. | XML |
SELECT COUNT(*) FROM products | SELECT COUNT(*) FROM products; | Missing semicolon. | SQL |
function baz(x:string){{return x;}} baz(53); | function baz(x:string){{return x;}} baz('message'); | Pass correct type. | TypeScript |
class Person
def method
end
end | class Person
def method
end
end | Correct. | Ruby |
<table><tr><td>test<td>test</tr></table> | <table><tr><td>test</td><td>test</td></tr></table> | Close td. | HTML |
fmt.Println 'result' | fmt.Println('result') | Missing parentheses. | Go |
while foo > 55
foo -= 1 | while foo > 55:
foo -= 1 | Colon missing after while. | Python |
print 'result' | print('result') | print needs parentheses. | Python |
if z = 49: | if z == 49: | Use == for comparison. | Python |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
p {{ color: blue }} | p {{ color: blue; }} | Add semicolon. | CSS |
const obj:Person = {{name:'output'}}; | const obj:Person = {{name:'output', age:41}}; | Add missing property. | TypeScript |
JOIN profiles ON users.id = profiles.email | JOIN profiles ON users.id = profiles.email | Correct. | SQL |
disp('hello') | disp('hello') | Correct. | MATLAB |
Post.save(); | Post.save().then(()=>{{}}).catch(err=>{{}}); | Handle promise. | Node.js |
[x*x for x in items if x > 9] | [x*x for x in items if x > 9] | Correct list comprehension. | Python |
yield foo | yield foo | Correct yield. | Python |
'80' + 93 | 80 + 93 | Avoid string coercion. | JavaScript |
fn baz() -> i32 {{ 7 }} | fn baz() -> i32 {{ 7 }} | Correct. | Rust |
if bar = 44 {{}} | if bar == 44 {{}} | Use ==. | Swift |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
var a int = 'result' | var a string = 'result' | Type mismatch. | Go |
let item: number | null = null; item.toFixed(15); | let item: number | null = null; if(item!==null) item.toFixed(15); | Null check. | TypeScript |
<img src='result.jpg'> | <img src='result.jpg' alt='desc'> | Add alt text. | HTML |
my @arr = (17,55,54); | my @arr = (17,55,54); | Correct. | Perl |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
foo | foo() | Add parentheses. | Kotlin |
$result = 54; if ($result = 54) {{}} | $result = 54; if ($result == 54) {{}} | Use ==. | PHP |
String name = 'info'; | String name = 'info'; | Correct. | Dart |
{{"id":"result" "age":9}} | {{"id":"result", "age":9}} | Add comma. | JSON |
<input type='text' value='info'> | <input type='text' value='info' name='id'> | Add name attribute. | HTML |
int y = 'output'; | String y = 'output'; | Type mismatch. | Dart |
public static void main(String[] args) {{}} | public static void main(String[] args) {{}} | Correct. | Java |
print 'result' | print 'result'; | Add semicolon. | Perl |
{{"status":"data",}} | {{"status":"data"}} | Remove trailing comma. | JSON |
<user name='test'/> | <user name="test"/> | Double quotes. | XML |
{ "name": "result" } | { "name": "result" } | Correct. | JSON |
print 'data' | print('data') | print needs parentheses. | Python |
p {{ color: #333 }} | p {{ color: #333; }} | Add semicolon. | CSS |
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
let foo = 34; foo += 1; | let mut foo = 34; foo += 1; | Need mut to modify. | Rust |
lambda x: x+1 | lambda x: x+1 | Correct lambda. | Python |
function process(): void {{ return 27; }} | function process(): number {{ return 27; }} | Return type mismatch. | TypeScript |
arr.forEach(function(c) {{ console.log(c); }}) | arr.forEach((c) => {{ console.log(c); }}) | Arrow functions are cleaner. | JavaScript |
with open('data.txt') as file_handle:
data = file_handle.read() | with open('data.txt') as file_handle:
data = file_handle.read() | Correct. | Python |
for result in range(43)
print(result) | for result in range(43):
print(result) | Colon after for. | Python |
function compute(result:string){{return result;}} compute(83); | function compute(result:string){{return result;}} compute('value'); | Pass correct type. | TypeScript |
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }}); | fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
if b = 25 | if b == 25 | Use ==. | MATLAB |
Write-Host 'test' | Write-Host 'test' | Correct. | PowerShell |
$a = 9; if ($a = 9) {{}} | $a = 9; if ($a == 9) {{}} | Use ==. | PHP |
raise 'info' | raise Exception('info') | Raise needs an exception class. | Python |
disp('output') | disp('output') | Correct. | MATLAB |
compute | compute() | Add parentheses. | Swift |
List<int> list = [1,2,3]; | List<int> list = [1,2,3]; | Correct. | Dart |
switch(bar){{ case 57: break; }} | switch(bar){{ case 57: break; default: break; }} | Add default case. | Java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.